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

Compiler crash with NoSuchElementException when combining "implicit class" and "AnyVal"/"case class" declaration #5667

Closed
scabug opened this issue Apr 13, 2012 · 6 comments

Comments

@scabug
Copy link

scabug commented Apr 13, 2012

scala> implicit case class Foo(i: Int)
error: 
     while compiling:  <console>
       current phase:  typer
     library version:  version 2.10.0-20120413-153403-c26ef91048
    compiler version:  version 2.10.0-20120413-153403-c26ef91048
  reconstructed args:  

uncaught exception during compilation: java.util.NoSuchElementException
java.util.NoSuchElementException: key not found: value Foo
	at scala.collection.MapLike$class.default(MapLike.scala:228)
	at scala.collection.AbstractMap.default(Map.scala:57)
	at scala.collection.mutable.HashMap.apply(HashMap.scala:63)
	at scala.tools.nsc.typechecker.MethodSynthesis$MethodSynth$class.addDerivedTrees(MethodSynthesis.scala:234)
	at scala.tools.nsc.typechecker.Namers$Namer.addDerivedTrees(Namers.scala:76)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$31.apply(Typers.scala:1658)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$31.apply(Typers.scala:1658)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$rewrappingWrapperTrees$1.apply(Typers.scala:1596)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$rewrappingWrapperTrees$1.apply(Typers.scala:1593)
	at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:247)
	at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:247)
	at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
	at scala.collection.immutable.List.foreach(List.scala:77)
	at scala.collection.TraversableLike$class.flatMap(TraversableLike.scala:247)
	at scala.collection.AbstractTraversable.flatMap(Traversable.scala:112)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1658)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$30.apply(Typers.scala:1568)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$30.apply(Typers.scala:1568)
	at scala.tools.nsc.typechecker.Typers$Typer.typerReportAnyContextErrors(Typers.scala:501)
	at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1567)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4462)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4812)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:2455)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49$$anonfun$50.apply(Typers.scala:2551)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49$$anonfun$50.apply(Typers.scala:2551)
	at scala.collection.immutable.List.loop$1(List.scala:163)
	at scala.collection.immutable.List.mapConserve(List.scala:179)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49.apply(Typers.scala:2551)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49.apply(Typers.scala:2550)
	at scala.tools.nsc.typechecker.Typers$Typer.withSavedContext(Typers.scala:510)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:2550)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1660)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$30.apply(Typers.scala:1568)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$30.apply(Typers.scala:1568)
	at scala.tools.nsc.typechecker.Typers$Typer.typerReportAnyContextErrors(Typers.scala:501)
	at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1567)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4462)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4812)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:2455)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49$$anonfun$50.apply(Typers.scala:2551)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49$$anonfun$50.apply(Typers.scala:2551)
	at scala.collection.immutable.List.loop$1(List.scala:163)
	at scala.collection.immutable.List.mapConserve(List.scala:179)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49.apply(Typers.scala:2551)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49.apply(Typers.scala:2550)
	at scala.tools.nsc.typechecker.Typers$Typer.withSavedContext(Typers.scala:510)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:2550)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1660)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$30.apply(Typers.scala:1568)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$30.apply(Typers.scala:1568)
	at scala.tools.nsc.typechecker.Typers$Typer.typerReportAnyContextErrors(Typers.scala:501)
	at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1567)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4462)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4812)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:2455)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49$$anonfun$50.apply(Typers.scala:2551)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49$$anonfun$50.apply(Typers.scala:2551)
	at scala.collection.immutable.List.loop$1(List.scala:163)
	at scala.collection.immutable.List.mapConserve(List.scala:179)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49.apply(Typers.scala:2551)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49.apply(Typers.scala:2550)
	at scala.tools.nsc.typechecker.Typers$Typer.withSavedContext(Typers.scala:510)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:2550)
	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1660)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$30.apply(Typers.scala:1568)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$30.apply(Typers.scala:1568)
	at scala.tools.nsc.typechecker.Typers$Typer.typerReportAnyContextErrors(Typers.scala:501)
	at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1567)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4462)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4812)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:2455)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49$$anonfun$50.apply(Typers.scala:2551)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49$$anonfun$50.apply(Typers.scala:2551)
	at scala.collection.immutable.List.loop$1(List.scala:163)
	at scala.collection.immutable.List.mapConserve(List.scala:179)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49.apply(Typers.scala:2551)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$49.apply(Typers.scala:2550)
	at scala.tools.nsc.typechecker.Typers$Typer.withSavedContext(Typers.scala:510)
	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:2550)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4455)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4812)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4870)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:96)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:423)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:88)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:88)
	at scala.collection.Iterator$class.foreach(Iterator.scala:697)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1124)
	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:88)
	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1305)
	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1278)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1272)
	at scala.tools.nsc.interpreter.IMain.compileSourcesKeepingRun(IMain.scala:455)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compileAndSaveRun(IMain.scala:837)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compile(IMain.scala:795)
	at scala.tools.nsc.interpreter.IMain$Request.compile(IMain.scala:968)
	at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:622)
	at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:589)
	at scala.tools.nsc.interpreter.ILoop.reallyInterpret$1(ILoop.scala:777)
	at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:831)
	at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:734)
	at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:598)
	at scala.tools.nsc.interpreter.ILoop.innerLoop$1(ILoop.scala:605)
	at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:608)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:911)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:873)
	at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:873)
	at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:155)
	at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:873)
	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:79)
	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:92)
	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
@scabug
Copy link
Author

scabug commented Apr 13, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5667?orig=1
Reporter: @soc
Affected Versions: 2.10.0
Attachments:

  • Test.scala (created on Apr 16, 2012 3:44:55 PM UTC, 133 bytes)
  • Test.scala (created on Apr 16, 2012 3:44:08 PM UTC, 124 bytes)

@scabug
Copy link
Author

scabug commented Apr 16, 2012

@dcsobral said:
This also happens when combining SIP-13 with SIP-15. I'm uploading a test case.

@scabug
Copy link
Author

scabug commented Apr 16, 2012

@dcsobral said:
Copy of SIP-13's test case, with just "extends AnyVal" added.

@scabug
Copy link
Author

scabug commented Apr 16, 2012

@dcsobral said:
Copy of SIP-13's test case with "class" turned into "case class".

@scabug
Copy link
Author

scabug commented May 3, 2012

@szeiger said:
A case class is not needed. The combination of implicit class + extends AnyVal (which would be illegal for a case class) also causes this error:

object Main {
  implicit class C(val s: StringContext) extends AnyVal
}

@scabug
Copy link
Author

scabug commented May 4, 2012

@paulp said:
5c84dc85bf

Fix for implicit class / value class collision.

New this week, on SCALA.

Implicit class: "Spin me up an implicit method with my name."
   Value class: "I need a companion object, pronto."
      Narrator: "All was well with this arrangement... UNTIL."

What happens when these two wacky SIPs get together in the very
same class? You'll laugh until, eventually, you cry! Weeknights
at 9:30pm, only on SCALA.

Closes SI-5667.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants