scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

regression in ClassDef quasiquotes in 2.11.2 under -Yrangepos #8771

Closed scabug closed 6 years ago

scabug commented 10 years ago
import scala.reflect.macros.whitebox._
import scala.language.experimental.macros

object Macros {
  def impl(c: Context)(x: c.Tree) = {
    import c.universe._
    val q"{ class $name(...$paramss) }" = x
    q"{ class $name(...$paramss) }"
  }

  def foo(x: Any): Any = macro impl
}
object Test extends App {
  Macros.foo {
    class X(x: Int)
  }
}
Test.scala:2: error: exception during macro expansion:
java.lang.UnsupportedOperationException: Position.point on NoPosition
    at scala.reflect.internal.util.Position.fail(Position.scala:17)
    at scala.reflect.internal.util.UndefinedPosition.point(Position.scala:95)
    at scala.reflect.internal.util.UndefinedPosition.point(Position.scala:90)
    at scala.reflect.internal.Positions$class.wrappingPos(Positions.scala:42)
    at scala.reflect.internal.SymbolTable.wrappingPos(SymbolTable.scala:16)
    at scala.reflect.internal.Positions$class.wrappingPos(Positions.scala:37)
    at scala.reflect.internal.SymbolTable.wrappingPos(SymbolTable.scala:16)
    at scala.reflect.internal.TreeGen.mkTemplate(TreeGen.scala:378)
    at scala.reflect.internal.ReificationSupport$ReificationSupportImpl$SyntacticClassDef$.apply(ReificationSupport.scala:341)
    at scala.reflect.internal.ReificationSupport$ReificationSupportImpl$SyntacticClassDef$.apply(ReificationSupport.scala:326)
    at Macros$.impl(Macros.scala:9)

  Macros.foo {
             ^
one error found
scabug commented 10 years ago

Imported From: https://issues.scala-lang.org/browse/SI-8771?orig=1 Reporter: @xeno-by Affected Versions: 2.11.2

scabug commented 10 years ago

@xeno-by said (edited on Aug 1, 2014 2:25:01 PM UTC): Works in 2.11.1, but not in 2.11.2.

Caused by the fact that paramss extracted in a quasiquote get a more precise position in 2.11.2 (a range position, as opposed to an offset position in earlier versions), which crashes TreeGen.mkTemplate when these argss are spliced into a new quasiquote.

scabug commented 10 years ago

@xeno-by said: A workaround here would be to call duplicate on paramss (i.e. to splice not ...$paramss, but ...${paramss.map(.map(.duplicate))}}. That will reset their positions to offset positions guaranteeing successful completion of mkTemplate.

scabug commented 9 years ago

@xeno-by said: This issue is automatically worked around for macro annotations in macro paradise versions 2.0.2-SNAPSHOT, 2.1.0-SNAPSHOT and 2.1.0-M3. See https://github.com/scalamacros/paradise/issues/53 for details.

ryan-williams commented 6 years ago

I believe I'm seeing this with Scala 2.11.11 and macro paradise 2.1.0. Can put together a repro if that's not known to be possible.

SethTisue commented 6 years ago

closing all quasiquotes tickets; see #10755