Scala Programming Language
  1. Scala Programming Language
  2. SI-5667

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

    Details

      Description

      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)
      
      1. Test.scala
        0.1 kB
        Daniel Sobral
      2. Test.scala
        0.1 kB
        Daniel Sobral

        Issue Links

          Activity

          Hide
          Daniel Sobral added a comment -

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

          Show
          Daniel Sobral added a comment - This also happens when combining SIP-13 with SIP-15. I'm uploading a test case.
          Hide
          Daniel Sobral added a comment -

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

          Show
          Daniel Sobral added a comment - Copy of SIP-13's test case, with just "extends AnyVal" added.
          Hide
          Daniel Sobral added a comment -

          Copy of SIP-13's test case with "class" turned into "case class".

          Show
          Daniel Sobral added a comment - Copy of SIP-13's test case with "class" turned into "case class".
          Hide
          Stefan Zeiger added a comment -

          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
          }
          
          Show
          Stefan Zeiger added a comment - 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 }
          Hide
          Paul Phillips added a comment -

          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.
          
          Show
          Paul Phillips added a comment - 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.

            People

            • Assignee:
              Paul Phillips
              Reporter:
              Simon Ochsenreither
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development