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

Quasiquotes with fresh names fail in combination with nested definitions #8047

Closed
scabug opened this issue Dec 8, 2013 · 5 comments
Closed

Quasiquotes with fresh names fail in combination with nested definitions #8047

scabug opened this issue Dec 8, 2013 · 5 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Dec 8, 2013

scala> q"do ${typeOf[String]} while(true)"

crashes the compiler due to owner chain corruption:

ReplGlobal.abort: symbol value $u does not exist in $line7.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw.<init>
error: symbol value $u does not exist in <init>
scala.reflect.internal.FatalError:
  symbol value $u does not exist in $line7.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw.<init>
     while compiling: <console>
        during phase: icode
     library version: version 2.11.0-20131208-210127-75cc6cf256
    compiler version: version 2.11.0-20131208-210127-75cc6cf256
  reconstructed args:

  last tree to typer: Ident($m$1)
       tree position: line 30 of <console>
            tree tpe: reflect.api.JavaMirrors$JavaMirror
              symbol: value $m$1
   symbol definition: $m$1: reflect.api.JavaMirrors$JavaMirror (a TermSymbol)
      symbol package: $line7
       symbol owners: value $m$1 -> constructor $read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$anonfun$1 -> <$anon: Function1>
           call site: constructor $read$$iw in package $line7

<Cannot read source file>
	at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:55)
	at scala.tools.nsc.Global.abort(Global.scala:263)
	at scala.tools.nsc.interpreter.IMain$$anon$1.scala$tools$nsc$interpreter$ReplGlobal$$super$abort(IMain.scala:235)
	at scala.tools.nsc.interpreter.ReplGlobal$class.abort(ReplGlobal.scala:20)
	at scala.tools.nsc.interpreter.IMain$$anon$1.abort(IMain.scala:235)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadIdent$1(GenICode.scala:884)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:890)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1121)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1119)
	at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:110)
	at scala.collection.immutable.List.foldLeft(List.scala:83)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadArguments(GenICode.scala:1119)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadApply3$1(GenICode.scala:693)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:703)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:923)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:915)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1121)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1119)
	at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:110)
	at scala.collection.immutable.List.foldLeft(List.scala:83)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadArguments(GenICode.scala:1119)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadApply6$1(GenICode.scala:774)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:808)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadQualifier(GenICode.scala:1080)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadApply1$1(GenICode.scala:609)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:634)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genStat(GenICode.scala:166)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genStat$1.apply(GenICode.scala:151)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genStat$1.apply(GenICode.scala:151)
	at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:110)
	at scala.collection.immutable.List.foldLeft(List.scala:83)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genStat(GenICode.scala:151)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:914)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:119)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:67)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:67)
	at scala.collection.immutable.List.foreach(List.scala:302)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:67)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:144)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:94)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:67)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:67)
	at scala.collection.immutable.List.foreach(List.scala:302)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:67)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:85)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:63)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.apply(GenICode.scala:59)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:424)
	at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:391)
	at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:391)
	at scala.collection.Iterator$class.foreach(Iterator.scala:743)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1174)
	at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:391)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.run(GenICode.scala:51)
	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1603)
	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1588)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1583)
	at scala.tools.nsc.interpreter.IMain.compileSourcesKeepingRun(IMain.scala:388)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compileAndSaveRun(IMain.scala:817)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compile(IMain.scala:776)
	at scala.tools.nsc.interpreter.IMain$Request.compile$lzycompute(IMain.scala:952)
	at scala.tools.nsc.interpreter.IMain$Request.compile(IMain.scala:947)
	at scala.tools.nsc.interpreter.IMain.compile(IMain.scala:531)
	at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:519)
	at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:517)
	at scala.tools.nsc.interpreter.ILoop$paste$.interpret(ILoop.scala:726)
	at scala.tools.nsc.interpreter.Pasted$PasteAnalyzer$$anonfun$run$1.apply(Pasted.scala:86)
	at scala.tools.nsc.interpreter.Pasted$PasteAnalyzer$$anonfun$run$1.apply(Pasted.scala:84)
	at scala.collection.immutable.List.foreach(List.scala:302)
	at scala.tools.nsc.interpreter.Pasted$PasteAnalyzer.run(Pasted.scala:84)
	at scala.tools.nsc.interpreter.Pasted.apply(Pasted.scala:98)
	at scala.tools.nsc.interpreter.ILoop$paste$.transcript(ILoop.scala:732)
	at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:782)
	at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:660)
	at scala.tools.nsc.interpreter.ILoop.processLine(ILoop.scala:427)
	at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:444)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:862)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:848)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:848)
	at scala.reflect.internal.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:95)
	at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:848)
	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:81)
	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:94)
	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:103)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
@scabug
Copy link
Author

@scabug scabug commented Dec 8, 2013

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

@scabug
Copy link
Author

@scabug scabug commented Dec 8, 2013

@densh said (edited on Dec 8, 2013 11:52:26 AM UTC):
That quasiquote expands into:

withFreshTermName("doWhile$")(((nn$1) => LabelDef(nn$1, List(), SyntacticBlock(List($iw.this.test(typeOf[String]({
  val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe;
  val $m: $u.Mirror = runtimeMirror(this.getClass().getClassLoader());
  $u.TypeTag.apply[String]($m, {
    final class $typecreator1 extends TypeCreator {
      def <init>(): $typecreator1 = {
        $typecreator1.super.<init>();
        ()
      };
      def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = {
        val $u: U = $m$untyped.universe;
        val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
        $u.TypeRef.apply($u.SingleType.apply($u.ThisType.apply($m.staticPackage("scala").asModule.moduleClass), $m.staticModule("scala.Predef")), $u.build.selectType($m.staticModule("scala.Predef").asModule.moduleClass, "String"), immutable.this.Nil)
      }
    };
    new $typecreator1()
  })
})), If(Literal(Constant(true)), SyntacticApplied(SyntacticIdent(nn$1, false), List(List())), Literal(Constant(()))))))))

Looks like problem of interaction between macros (crash is within expansion of typeOf).

@scabug
Copy link
Author

@scabug scabug commented Dec 8, 2013

@densh said:
Minimized. The crash isn't specific to quasiquotes.

@scabug
Copy link
Author

@scabug scabug commented Dec 9, 2013

@densh said:
Apparently what Eugene meant by his original non-descruptive bug report is that quasiquotes also suffer from owner chain corruption. Talk about clarity of intent here.

@scabug
Copy link
Author

@scabug scabug commented Jan 14, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants