Skip to content

CyclicReference exceptions when walking owners and checking flags #8877

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
manojo opened this issue May 4, 2020 · 0 comments · Fixed by #9984
Closed

CyclicReference exceptions when walking owners and checking flags #8877

manojo opened this issue May 4, 2020 · 0 comments · Fixed by #9984

Comments

@manojo
Copy link
Contributor

manojo commented May 4, 2020

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

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.

3 participants