Closed
Description
I am trying to write a more semantic port of the findOwner
function of the dotty version in sourcecode. This causes a CyclicReference
exception.
Minimized code
object Foo {
inline def genOwner: String = ${ util.Macros.genOwnerImpl() }
}
// main
@main def entry = {
println(Foo.genOwner)
}
//macros
import scala.quoted._
import scala.tasty.Reflection
object Macros {
//a specialization of the `findOwner` function from `sourcecode` for our purposes
private def firstNonSyntheticOwner(c: Reflection, s : c.Symbol): c.Symbol = {
import c.{given _}
if (s.flags.is(c.Flags.Synthetic)) firstNonSyntheticOwner(c, s.owner)
else s
}
def genOwnerImpl()(using qctx: QuoteContext): Expr[String] = {
Expr(firstNonSyntheticOwner(qctx.tasty, qctx.tasty.rootContext.owner).name)
}
}
Output (click arrow to expand)
[error] 16 | println(Foo.genOwner)
[error] | ^^^^^^^^^^^^
[error] |Exception occurred while executing macro expansion.
[error] |dotty.tools.dotc.core.CyclicReference:
[error] | at dotty.tools.dotc.core.CyclicReference$.apply(TypeErrors.scala:156)
[error] | at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:257)
[error] | at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:186)
[error] | at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:188)
[error] | at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:446)
[error] | at dotty.tools.dotc.core.SymDenotations$SymDenotation.flags(SymDenotations.scala:158)
[error] | at dotty.tools.dotc.tastyreflect.ReflectionCompilerInterface.Symbol_flags(ReflectionCompilerInterface.scala:1669)
[error] | at dotty.tools.dotc.tastyreflect.ReflectionCompilerInterface.Symbol_flags(ReflectionCompilerInterface.scala:1669)
[error] | at scala.tasty.Reflection$SymbolOps$.flags(Reflection.scala:2129)
[error] | at Macros$.firstNonSyntheticOwner(SourceContextMacros.scala:11)
[error] | at Macros$.genOwnerImpl(SourceContextMacros.scala:16)
[error] |
[error] | This location contains code that was inlined from Main.scala:16
[error] one error found