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

An implicit definition with the same name as an implicit class crashes the compiler

    Details

      Description

      Self-explanatory:

      object Test {
        
        implicit class Foo
        
        implicit def Foo = new Foo
        
      }
      

      produces:

      error: 
           while compiling:  test.scala
             current phase:  typer
           library version:  version 2.10.0-20120501-095224-ce04a62391
          compiler version:  version 2.10.0-20120501-095224-ce04a62391
        reconstructed args:  
      
      uncaught exception during compilation: java.util.NoSuchElementException
      error: 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:237)
      	at scala.tools.nsc.typechecker.Namers$Namer.addDerivedTrees(Namers.scala:76)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$44.apply(Typers.scala:1705)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$44.apply(Typers.scala:1705)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$rewrappingWrapperTrees$1.apply(Typers.scala:1643)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$rewrappingWrapperTrees$1.apply(Typers.scala:1640)
      	at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:243)
      	at scala.collection.TraversableLike$$anonfun$flatMap$1.apply(TraversableLike.scala:243)
      	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:243)
      	at scala.collection.AbstractTraversable.flatMap(Traversable.scala:105)
      	at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1705)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$43.apply(Typers.scala:1615)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$43.apply(Typers.scala:1615)
      	at scala.tools.nsc.typechecker.Typers$Typer.typerReportAnyContextErrors(Typers.scala:501)
      	at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1614)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4630)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4988)
      	at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:2537)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$63$$anonfun$64.apply(Typers.scala:2633)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$63$$anonfun$64.apply(Typers.scala:2633)
      	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$63.apply(Typers.scala:2633)
      	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$63.apply(Typers.scala:2632)
      	at scala.tools.nsc.typechecker.Typers$Typer.withSavedContext(Typers.scala:510)
      	at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:2632)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4623)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4988)
      	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5046)
      	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:97)
      	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:432)
      	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:89)
      	at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:89)
      	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:89)
      	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1336)
      	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1309)
      	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1303)
      	at scala.tools.nsc.Global$Run.compile(Global.scala:1436)
      	at scala.tools.nsc.Driver.doCompile(Driver.scala:31)
      	at scala.tools.nsc.Main$.doCompile(Main.scala:81)
      	at scala.tools.nsc.Driver.process(Driver.scala:52)
      	at scala.tools.nsc.Driver.main(Driver.scala:65)
      	at scala.tools.nsc.Main.main(Main.scala)
      

        Activity

        Hide
        Adriaan Moors added a comment -

        before calling enterImplicitWrapper, we should check that the class meets the criteria of an implicit class (exactly one primary constructor argument)

        https://github.com/scala/scala/blob/master/src/compiler/scala/tools/nsc/typechecker/Namers.scala#L638

        Show
        Adriaan Moors added a comment - before calling enterImplicitWrapper, we should check that the class meets the criteria of an implicit class (exactly one primary constructor argument) https://github.com/scala/scala/blob/master/src/compiler/scala/tools/nsc/typechecker/Namers.scala#L638
        Hide
        Paul Phillips added a comment -

        ca74659bb0

        Show
        Paul Phillips added a comment - ca74659bb0

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Aleksandar Prokopec
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development