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

malformed use of "f" string interpolator slays compiler #7653

Closed
scabug opened this issue Jul 12, 2013 · 9 comments
Closed

malformed use of "f" string interpolator slays compiler #7653

scabug opened this issue Jul 12, 2013 · 9 comments
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jul 12, 2013

the poison pill is:

f"%d"()

here's a stack trace from 2.11.0-M3; the results in 2.10.2 are similar


scala> f"%d"()
error: 
     while compiling: <console>
        during phase: typer
     library version: version 2.11.0-M3
    compiler version: version 2.11.0-M3
  reconstructed args: 

  last tree to typer: Apply(macro method f)
              symbol: macro method f in class StringContext (flags: <method> <macro> <triedcooking>)
   symbol definition: def f(args: Any*): String
       symbol owners: macro method f -> class StringContext -> package scala
      context owners: value res2 -> object $iw -> object $iw -> object $read -> package $line5

== Enclosing template or block ==

Template( // val <local $iw>: <notype>
  "java.lang.Object" // parents
  ValDef(
    private
    "_"
    <tpt>
    <empty>
  )
  // 2 statements
  DefDef( // def <init>: <?>
    <method>
    "<init>"
    []
    List(Nil)
    <tpt>
    Block(
      Apply(
        super."<init>"
        Nil
      )
      ()
    )
  )
  ValDef( // private[this] val res2: <?>
    private <local>
    "res2"
    <tpt>
    Apply(
      Apply(
        StringContext("%d")."f"
        Nil
      )
      Nil
    )
  )
)

uncaught exception during compilation: NullPointerException @ scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:1097)
java.lang.NullPointerException
	at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:1097)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5319)
	at scala.tools.nsc.interpreter.ReplGlobal$$anon$1$$anon$2.typed(ReplGlobal.scala:36)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$91.apply(Typers.scala:4447)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$91.apply(Typers.scala:4447)
	at scala.tools.nsc.typechecker.Typers$Typer.silent(Typers.scala:662)
	at scala.tools.nsc.typechecker.Typers$Typer.normalTypedApply$1(Typers.scala:4446)
	at scala.tools.nsc.typechecker.Typers$Typer.typedApply$1(Typers.scala:4499)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5230)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5301)
	at scala.tools.nsc.interpreter.ReplGlobal$$anon$1$$anon$2.typed(ReplGlobal.scala:36)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5373)
	at scala.tools.nsc.typechecker.Typers$Typer.computeType(Typers.scala:5458)
	at scala.tools.nsc.typechecker.Namers$Namer.assignTypeToTree(Namers.scala:831)
	at scala.tools.nsc.typechecker.Namers$Namer.valDefSig(Namers.scala:1299)
	at scala.tools.nsc.typechecker.Namers$Namer.getSig$1(Namers.scala:1444)
	at scala.tools.nsc.typechecker.Namers$Namer.typeSig(Namers.scala:1453)
	at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply$mcV$sp(Namers.scala:733)
	at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply(Namers.scala:732)
	at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply(Namers.scala:732)
	at scala.tools.nsc.typechecker.Namers$Namer.scala$tools$nsc$typechecker$Namers$Namer$$logAndValidate(Namers.scala:1480)
	at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1.apply(Namers.scala:732)
	at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1.apply(Namers.scala:724)
	at scala.tools.nsc.typechecker.Namers$$anon$1.completeImpl(Namers.scala:1595)
	at scala.tools.nsc.typechecker.Namers$LockingTypeCompleter$class.complete(Namers.scala:1603)
	at scala.tools.nsc.typechecker.Namers$$anon$1.complete(Namers.scala:1593)
	at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1310)
	at scala.reflect.internal.Symbols$Symbol.initialize(Symbols.scala:1446)
	at scala.tools.nsc.typechecker.MethodSynthesis$MethodSynth$class.addDerivedTrees(MethodSynthesis.scala:193)
	at scala.tools.nsc.typechecker.Namers$Namer.addDerivedTrees(Namers.scala:52)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$32.apply(Typers.scala:1953)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$32.apply(Typers.scala:1953)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$rewrappingWrapperTrees$1.apply(Typers.scala:1894)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$rewrappingWrapperTrees$1.apply(Typers.scala:1891)
	at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:252)
	at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:252)
	at scala.collection.immutable.List.foreach(List.scala:302)
	at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:252)
	at scala.collection.AbstractTraversable.flatMap(Traversable.scala:104)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1953)
	at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1831)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5250)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5301)
	at scala.tools.nsc.interpreter.ReplGlobal$$anon$1$$anon$2.typed(ReplGlobal.scala:36)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2858)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$59.apply(Typers.scala:2962)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$59.apply(Typers.scala:2962)
	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:2962)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1966)
	at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1831)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5250)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5301)
	at scala.tools.nsc.interpreter.ReplGlobal$$anon$1$$anon$2.typed(ReplGlobal.scala:36)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2858)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$59.apply(Typers.scala:2962)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$59.apply(Typers.scala:2962)
	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:2962)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1966)
	at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1831)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5250)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5301)
	at scala.tools.nsc.interpreter.ReplGlobal$$anon$1$$anon$2.typed(ReplGlobal.scala:36)
	at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2858)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$59.apply(Typers.scala:2962)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$59.apply(Typers.scala:2962)
	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:2962)
	at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:4939)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5253)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5301)
	at scala.tools.nsc.interpreter.ReplGlobal$$anon$1$$anon$2.typed(ReplGlobal.scala:36)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5360)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:99)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:415)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:91)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:90)
	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:90)
	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1520)
	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1495)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1491)
	at scala.tools.nsc.interpreter.IMain.compileSourcesKeepingRun(IMain.scala:409)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compileAndSaveRun(IMain.scala:829)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compile(IMain.scala:788)
	at scala.tools.nsc.interpreter.IMain$Request.compile$lzycompute(IMain.scala:933)
	at scala.tools.nsc.interpreter.IMain$Request.compile(IMain.scala:928)
	at scala.tools.nsc.interpreter.IMain.compile(IMain.scala:551)
	at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:539)
	at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:537)
	at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:574)
	at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:619)
	at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:531)
	at scala.tools.nsc.interpreter.ILoop.processLine(ILoop.scala:387)
	at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:404)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:687)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:673)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:673)
	at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:95)
	at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:673)
	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)

#6829 and #7001 appear similar, but they are fixed and this is not

@scabug
Copy link
Author

scabug commented Jul 12, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7653?orig=1
Reporter: @SethTisue
Affected Versions: 2.10.2
See #7001, #6829

@scabug
Copy link
Author

scabug commented Jul 12, 2013

@SethTisue said:
the d isn't necessary, {{f"%"()}}'s a crasher too

@scabug
Copy link
Author

scabug commented Jul 16, 2013

@retronym said:
This lies at the dark heart of Typer#adapt, insertApply. Predef.any2StringAdd seems to be a passenger on the ride.

Notice below we get the error reported if we manually write apply

scala> import reflect.macros.Context, language.experimental._
import reflect.macros.Context
import language.experimental._

scala>  def impl(c: Context) = { c.error(c.macroApplication.pos, "."); c.literal("") }
impl: (c: scala.reflect.macros.Context)c.Expr[String]

scala> def m = macro impl
defined term macro m: String

scala> m.apply()
<console>:14: error: .
              m.apply()
              ^

scala> m()
java.lang.NullPointerException

@scabug
Copy link
Author

scabug commented Jul 16, 2013

@scabug
Copy link
Author

scabug commented Oct 15, 2013

@gkossakowski said:
Unassigning and rescheduling to M7 as previous deadline was missed.

@scabug
Copy link
Author

scabug commented Aug 5, 2014

@gkossakowski said:
The 2.11.2 is out so I'm rescheduling the issue for 2.11.3.

@scabug
Copy link
Author

scabug commented Nov 4, 2014

@retronym said:
Updating fix-by version to 2.11.5.

@scabug
Copy link
Author

scabug commented Jun 6, 2015

@som-snytt said:
The poison pill and JZ's example progressed in 2.11.4, belying the update fix-by to 2.11.5.

@scabug
Copy link
Author

scabug commented Jun 7, 2015

@SethTisue said:
thanks for the update Som. I verified that 2.11.4 gives reasonable error messages (and so does 2.11.6).

@scabug scabug closed this as completed Jun 7, 2015
@scabug scabug added this to the 2.11.4 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants