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

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

Closed
scabug opened this issue May 1, 2012 · 3 comments
Closed
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented May 1, 2012

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)
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 1, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5728?orig=1
Reporter: @axel22
Affected Versions: 2.10.0-M3

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 1, 2012

@adriaanm said:
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

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented May 3, 2012

@paulp said:
ca74659bb0

@scabug scabug closed this May 3, 2012
@scabug scabug added this to the 2.10.0 milestone Apr 7, 2017
@adriaanm adriaanm added implicit and removed implicit implicits labels Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.