scala / bug

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

a crasher when a macro impl defined with a wrong paramtype is trying to expand #8438

Open scabug opened 10 years ago

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

object Macros {
  def impl(c: Context)(t: Any): c.Tree = c.universe.Literal(c.universe.Constant(()))
  def foo(t: Any): Any = macro impl
}
object Test extends App {
  Macros.foo(42)
}
10:24 ~/Projects/Master/sandbox (master)$ ss
error: unexpected fingerprint Other in MacroImplBinding(false,true,Macros$,impl,List(List(Other), List(Other)),List()) with paramss being List(List(value t)) corresponding to arg 42 in List(List(42))
error: scala.reflect.internal.FatalError: unexpected fingerprint Other in MacroImplBinding(false,true,Macros$,impl,List(List(Other), List(Other)),List()) with paramss being List(List(value t)) corresponding to arg 42 in List(List(42))
    at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:58)
    at scala.tools.nsc.Global.abort(Global.scala:269)
    at scala.tools.nsc.typechecker.Macros$$anonfun$17$$anonfun$18.apply(Macros.scala:421)
    at scala.tools.nsc.typechecker.Macros$$anonfun$17$$anonfun$18.apply(Macros.scala:416)
    at scala.reflect.internal.util.Collections$class.mapWithIndex(Collections.scala:190)
    at scala.reflect.internal.SymbolTable.mapWithIndex(SymbolTable.scala:16)
    at scala.tools.nsc.typechecker.Macros$$anonfun$17.apply(Macros.scala:416)
    at scala.tools.nsc.typechecker.Macros$$anonfun$17.apply(Macros.scala:407)
    at scala.reflect.internal.util.Collections$class.map3(Collections.scala:123)
    at scala.reflect.internal.SymbolTable.map3(SymbolTable.scala:16)
    at scala.tools.nsc.typechecker.Macros$class.calculateMacroArgs$1(Macros.scala:407)
    at scala.tools.nsc.typechecker.Macros$class.standardMacroArgs(Macros.scala:476)
    at scala.tools.nsc.Global$$anon$1.standardMacroArgs(Global.scala:459)
    at scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$10.default(AnalyzerPlugins.scala:390)
    at scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$10.default(AnalyzerPlugins.scala:387)
    at scala.tools.nsc.typechecker.AnalyzerPlugins$class.invoke(AnalyzerPlugins.scala:359)
    at scala.tools.nsc.typechecker.AnalyzerPlugins$class.pluginsMacroArgs(AnalyzerPlugins.scala:387)
    at scala.tools.nsc.Global$$anon$1.pluginsMacroArgs(Global.scala:459)
    at scala.tools.nsc.typechecker.Macros$class.macroArgs(Macros.scala:368)
    at scala.tools.nsc.Global$$anon$1.macroArgs(Global.scala:459)
    at scala.tools.nsc.typechecker.Macros$class.macroExpandWithRuntime(Macros.scala:739)
    at scala.tools.nsc.Global$$anon$1.macroExpandWithRuntime(Global.scala:459)
    at scala.tools.nsc.typechecker.Macros$MacroExpander$$anonfun$expand$1.apply(Macros.scala:563)
    at scala.tools.nsc.typechecker.Macros$MacroExpander$$anonfun$expand$1.apply(Macros.scala:556)
    at scala.tools.nsc.Global.withInfoLevel(Global.scala:197)
    at scala.tools.nsc.typechecker.Macros$MacroExpander.expand(Macros.scala:555)
    at scala.tools.nsc.typechecker.Macros$MacroExpander.apply(Macros.scala:543)
    at scala.tools.nsc.typechecker.Macros$class.standardMacroExpand(Macros.scala:704)
    at scala.tools.nsc.Global$$anon$1.standardMacroExpand(Global.scala:459)
    at scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$9.default(AnalyzerPlugins.scala:382)
    at scala.tools.nsc.typechecker.AnalyzerPlugins$$anon$9.default(AnalyzerPlugins.scala:379)
    at scala.tools.nsc.typechecker.AnalyzerPlugins$class.invoke(AnalyzerPlugins.scala:359)
    at scala.tools.nsc.typechecker.AnalyzerPlugins$class.pluginsMacroExpand(AnalyzerPlugins.scala:379)
    at scala.tools.nsc.Global$$anon$1.pluginsMacroExpand(Global.scala:459)
    at scala.tools.nsc.typechecker.Macros$class.macroExpand(Macros.scala:697)
    at scala.tools.nsc.Global$$anon$1.macroExpand(Global.scala:459)
    at scala.tools.nsc.typechecker.Typers$Typer.vanillaAdapt$1(Typers.scala:1112)
    at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:1167)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5317)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5330)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5277)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5281)
    at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5359)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2998)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3102)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3102)
    at scala.collection.immutable.List.loop$1(List.scala:172)
    at scala.collection.immutable.List.mapConserve(List.scala:188)
    at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3102)
    at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1904)
    at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1791)
    at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5217)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5266)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5303)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5330)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5277)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5281)
    at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5359)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2998)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3102)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$62.apply(Typers.scala:3102)
    at scala.collection.immutable.List.loop$1(List.scala:172)
    at scala.collection.immutable.List.mapConserve(List.scala:188)
    at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3102)
    at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:4926)
    at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5219)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5266)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5303)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5330)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5277)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5281)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5355)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:102)
    at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:430)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:94)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:93)
    at scala.collection.Iterator$class.foreach(Iterator.scala:743)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1174)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:93)
    at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1625)
    at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1610)
    at scala.tools.nsc.Global$Run.compileSources(Global.scala:1605)
    at scala.tools.nsc.Global$Run.compile(Global.scala:1703)
    at scala.tools.nsc.Driver.doCompile(Driver.scala:34)
    at scala.tools.nsc.MainClass.doCompile(Main.scala:23)
    at scala.tools.nsc.Driver.process(Driver.scala:55)
    at scala.tools.nsc.Driver.main(Driver.scala:68)
    at scala.tools.nsc.Main.main(Main.scala)
scabug commented 10 years ago

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

scabug commented 10 years ago

@xeno-by said: Despite a scary stacktrace, this error is caused by the fact that the macro shouldn't have even compiled, because its impl has a parameter of type Any, not, say, c.Expr[Any]. Therefore I don't think this should block a release.

som-snytt commented 6 years ago

I just encountered this while typing in a quick partest. Wasted some minutes because I don't write macros every day, or as they're now called, "old macros."

Despite the scary stacktrace, no one will miss old macros.