Skip to content

Stack Overflow when printing Inferred type #9251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rssh opened this issue Jun 26, 2020 · 1 comment · Fixed by #9265
Closed

Stack Overflow when printing Inferred type #9251

rssh opened this issue Jun 26, 2020 · 1 comment · Fixed by #9265
Assignees

Comments

@rssh
Copy link
Contributor

rssh commented Jun 26, 2020

Minimized code

File A:

package cps

import scala.quoted._

trait CpsMonad[F[_]]

trait ComputationBound[T]

implicit object ComputationBoundMonad extends CpsMonad[ComputationBound]

inline def async[F[_]](using am:CpsMonad[F]): Async.InferAsyncArg[F] =
   new Async.InferAsyncArg[F]

object Async {

class InferAsyncArg[F[_]](using am:CpsMonad[F]) {

       inline def apply[T](inline expr: T):Unit =
       ${
         Async.checkPrintTypeImpl[F,T]('expr)
        }

 }


  def checkPrintTypeImpl[F[_]:Type,T:Type](f: Expr[T])(using qctx: QuoteContext): Expr[Unit] =
    import qctx.tasty._

    def uninline(t:Term):Term =
      t match
        case Inlined(_,_,x) => uninline(x)
        case _ => t


    val fu = uninline(f.unseal)
    fu match
      case Block(_,Apply(TypeApply(Select(q,n),tparams),List(param))) =>
        param.tpe match
          case AppliedType(tp,tparams1) =>
            val fType = summon[quoted.Type[F]]
            val ptp = tparams1.tail.head
            val ptpTree = Inferred(AppliedType(fType.unseal.tpe,List(ptp)))
            println("res:"+ptpTree.show)
          case None =>
            println(s"tpe=${param.tpe} is not AppliedType")
        '{ () }
      case _ => ???

}

in file B

package cps

val c = async[ComputationBound] {
  List(1,2,3,4).collectFirst { case x if x > 0 => x > 3 }
}

Output

[error] -- Error: /Users/rssh/work/oss/dotty-cps/dotty-cps/src/test/scala/cps/TestCBS1ShiftIterableOps.scala:3:36 
[error] 3 |     val c = async[ComputationBound]{
[error]   |             ^
[error]   |             Exception occurred while executing macro expansion.
[error]   |             java.lang.StackOverflowError
[error]   |
[error]   | 

Expectation

Something will be printed during macro evaluation

@rssh rssh added the itype:bug label Jun 26, 2020
@rssh
Copy link
Contributor Author

rssh commented Jun 26, 2020

dotty-cps-minimized-stackowerflow-in-type-show.tar.gz
[project with this two files and sbt build]

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 1, 2020
@nicolasstucki nicolasstucki linked a pull request Jul 1, 2020 that will close this issue
nicolasstucki added a commit that referenced this issue Jul 1, 2020
Fix #9251: Print applied lambda types directly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants