Skip to content

Stack Overflow when printing Inferred type #9251

Closed
@rssh

Description

@rssh

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions