Skip to content

REPL crash when compiling lambda to anonymous class #5345

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

Closed
Duhemm opened this issue Oct 31, 2018 · 2 comments
Closed

REPL crash when compiling lambda to anonymous class #5345

Duhemm opened this issue Oct 31, 2018 · 2 comments

Comments

@Duhemm
Copy link
Contributor

Duhemm commented Oct 31, 2018

scala> def x[A, B]: ImplicitConverter[A, B] = _ => ???                                                                                                                                                                                                                                                                        
Exception in thread "main" java.lang.AssertionError: assertion failed: private method $anonfun in rs$line$1 accessed from method apply in null                                                                                                                                                                                
        at scala.Predef$.assert(Predef.scala:219)                                                                                                                                                                                                                                                                             
        at dotty.tools.dotc.transform.ExpandPrivate.ensurePrivateAccessible(ExpandPrivate.scala:89)                                                                                                                                                                                                                           
        at dotty.tools.dotc.transform.ExpandPrivate.transformSelect(ExpandPrivate.scala:99)                                                                                                                                                                                                                                   
        at dotty.tools.dotc.transform.ExpandPrivate.transformSelect(ExpandPrivate.scala:32)                                                                                                                                                                                                                                   
        at dotty.tools.dotc.transform.MegaPhase.goSelect(MegaPhase.scala:562)                                                                                                                                                                                                                                                 
        at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:229)                                                                                                                                                                                                                                         
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:391)                                                                                                                                                                                                                                            
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:270)                                                                                                                                                                                                                                       
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:392)                                                                                                                                                                                                                                            
        at dotty.tools.dotc.transform.MegaPhase.mapDefDef$1(MegaPhase.scala:245)                                                                                                                                                                                                                                              
        at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:248)                                                                                                                                                                                                                                         
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:391)                                                                                                                                                                                                                                            
        at dotty.tools.dotc.transform.MegaPhase.transformStat$1(MegaPhase.scala:400)                                                                                                                                                                                                                                          
        at dotty.tools.dotc.transform.MegaPhase.$anonfun$transformStats$2(MegaPhase.scala:405)                                                                                                                                                                                                                                
        at scala.collection.immutable.List.mapConserve(List.scala:175)
        at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:405)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:339)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:392)
        at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:251)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:391)
        at dotty.tools.dotc.transform.MegaPhase.transformStat$1(MegaPhase.scala:400)
        at dotty.tools.dotc.transform.MegaPhase.$anonfun$transformStats$2(MegaPhase.scala:405)
        at scala.collection.immutable.List.mapConserve(List.scala:175)
        at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:405)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:339)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:392)
        at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:251)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:391)
        at dotty.tools.dotc.transform.MegaPhase.transformStat$1(MegaPhase.scala:400)
        at dotty.tools.dotc.transform.MegaPhase.$anonfun$transformStats$2(MegaPhase.scala:405)
        at scala.collection.immutable.List.mapConserve(List.scala:175)
        at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:405)
        at dotty.tools.dotc.transform.MegaPhase.mapPackage$1(MegaPhase.scala:356)
        at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:359)
        at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:392)
        at dotty.tools.dotc.transform.MegaPhase.transformUnit(MegaPhase.scala:411)
        at dotty.tools.dotc.transform.MegaPhase.run(MegaPhase.scala:423)
        at dotty.tools.dotc.core.Phases$Phase.$anonfun$runOn$1(Phases.scala:297)
        at scala.collection.immutable.List.map(List.scala:282)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:295)
        at dotty.tools.dotc.core.Phases$Phase.runOn$(Phases.scala:294)
        at dotty.tools.dotc.transform.MegaPhase.runOn(MegaPhase.scala:137)
        at dotty.tools.dotc.Run.$anonfun$compileUnits$3(Run.scala:172)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.util.Stats$.trackTime(Stats.scala:49)
        at dotty.tools.dotc.Run.$anonfun$compileUnits$2(Run.scala:169)
        at dotty.tools.dotc.Run.$anonfun$compileUnits$2$adapted(Run.scala:167)
        at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:32)
        at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:29)
        at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:194)         
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:167)                        
        at dotty.tools.dotc.Run.$anonfun$compileUnits$1(Run.scala:192)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:90)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:147)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:139)
        at dotty.tools.repl.ReplCompiler.runCompilationUnit(ReplCompiler.scala:141)
        at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:150)
        at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:213)
        at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:182)
        at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:127)
        at dotty.tools.repl.ReplDriver.$anonfun$runUntilQuit$2(ReplDriver.scala:130)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
        at scala.Console$.withErr(Console.scala:192)
        at dotty.tools.repl.ReplDriver.$anonfun$withRedirectedOutput$1(ReplDriver.scala:143)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:58)
        at scala.Console$.withOut(Console.scala:163)
        at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:143)
        at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:130)
        at dotty.tools.repl.Main$.main(Main.scala:6)
        at dotty.tools.repl.Main.main(Main.scala)

This doesn't happen outside the REPL, or when we don't use ImplicitConverter.

@allanrenucci
Copy link
Contributor

allanrenucci commented Oct 31, 2018

This is not specific to ImplicitConverter. This is another occurence of #4051.

This happens when we exercice the following code path in the REPL: https://github.com/lampepfl/dotty/blob/0fcbfdb752fa22ed1b9c5f5ebf99382aa0f76ead/compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala#L86-L88
Here ctx.owner.sourceFile happens to be null in the REPL.

We exercice this code path when we compile a lambda to an anonymous class:

scala> trait Foo extends Function1[Int, Int]; (_ => 1): Foo                                                                                                                                            
Exception in thread "main" java.lang.AssertionError: assertion failed: private method $anonfun in rs$line$2 accessed from method apply in null
	at scala.Predef$.assert(Predef.scala:219)
	at dotty.tools.dotc.transform.ExpandPrivate.ensurePrivateAccessible(ExpandPrivate.scala:89)
	at dotty.tools.dotc.transform.ExpandPrivate.transformSelect(ExpandPrivate.scala:99)
	at dotty.tools.dotc.transform.ExpandPrivate.transformSelect(ExpandPrivate.scala:32)
	...

@allanrenucci allanrenucci changed the title REPL crash when using ImplicitConverter REPL crash when compiling lambda to anonymous class Oct 31, 2018
@smarter
Copy link
Member

smarter commented Jan 28, 2019

Already fixed, regression test in #5800.

@smarter smarter closed this as completed Jan 28, 2019
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

3 participants