Skip to content
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

Illegal cyclic reference in 2.12 when typechecking in macro #100

Open
cornerman opened this issue Jun 29, 2017 · 0 comments
Open

Illegal cyclic reference in 2.12 when typechecking in macro #100

cornerman opened this issue Jun 29, 2017 · 0 comments

Comments

@cornerman
Copy link

I have a macro annotation with paradise, which typechecks an annotated ValDef. It compiles in scala 2.11.11, but gives an illegal cyclic reference error in 2.12.2. I am not sure whether this a scala bug or because of paradise. A short example:

import scala.reflect.macros.whitebox.Context
import scala.language.experimental.macros
import scala.annotation.{StaticAnnotation, compileTimeOnly}

object Macro {
  def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
    import c.universe._

    annottees.map(_.tree) match {
      case (valDef: ValDef) :: _ =>

        //this works in scala 2.11.11 and 2.12.2
        c.typecheck(valDef, withMacrosDisabled = true)

        //this works in scala 2.11.11, but not in 2.12.2
        val unmodValDef = ValDef(Modifiers(), valDef.name, valDef.tpt, valDef.rhs)
        c.typecheck(unmodValDef, withMacrosDisabled = true)

        annottees.head
      case _ => c.abort(c.enclosingPosition, "unsupported annotation")
    }
  }
}

@compileTimeOnly("only for compile time expansion")
class example extends StaticAnnotation {
  def macroTransform(annottees: Any*): Any = macro Macro.impl
}

Using this annotation on a val:

// using a trait instead of a class compiles in 2.12.2
class Wrap {
  @example val x: Int = 1
}

In 2.12.2, this leads to an illegal cyclic reference error:

[error] [0] /scala/ExampleSpec.scala:7: illegal cyclic reference involving class Wrap

This is the failing code:

val unmodValDef = ValDef(Modifiers(), valDef.name, valDef.tpt, valDef.rhs)
//this works in scala 2.11.11, but not in 2.12.2
c.typecheck(unmodValDef, withMacrosDisabled = true)

An example project with repro.

SethTisue pushed a commit to scalacommunitybuild/paradise that referenced this issue Nov 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant