scala3
scala3 copied to clipboard
Trees quoted macros doesn't resolve the constructor rhs
Compiler version
3.2.1-RC1-bin-20220705-9bb3108-NIGHTLY-git-9bb3108
Minimized code
package test
class Foo(val name: String)
object Bar extends Foo("bar")
object Macros {
import scala.quoted.{Expr, Quotes, Type}
inline def show[A]: String = ${ showImpl[A] }
def showImpl[A](using tpe: Type[A], q: Quotes): Expr[String] = {
import q.reflect.*
val repr = TypeRepr.of[A](using tpe)
val tpeSym = repr.typeSymbol
Expr(tpeSym.tree.show)
}
}
Output
> _root_.test.Macros.show[_root_.test.Bar.type]
val res0: String = @scala.annotation.internal.SourceFile("macros/src/main/scala-3/enumeratum/Foo.scala") object Bar extends test.Foo { this: test.Bar.type =>
}
Expectation
Following Tree should be resolved from the super call.
Literal(Constant("bar"))
Alternatives
Having the macro from the reproducer in a separate file doesn't help (same result).
Using repr.typeSymbol.companionModule instead of repr.typeSymbol resolves as bellow:
"lazy val Bar: test.Bar.type"
Try repr.typeSymbol.primaryConstructor doesn't help much:
"def this()"
Even trying to patter-match on it:
tpeSym.tree match {
case DefDef(_, _, _, rhs) =>
println(s"Constructor rhs = $rhs")
case _ =>
}
// => "Constructor rhs = None"
Maybe related to #15799
Cause may be same as for https://github.com/lampepfl/dotty/issues/14195 but none of the workaround is sufficient
That's quite a blocker. I'm trying to debug it, but there is no test that can be easily executed while developing quotes impl in this code base.
Confirmed to be related to -Yretain-trees