Skip to content

user defined anonymous PolyFunction causes crash at ElimPolyFunction, GenBCode #10075

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
bishabosha opened this issue Oct 23, 2020 · 2 comments · Fixed by #18920
Closed

user defined anonymous PolyFunction causes crash at ElimPolyFunction, GenBCode #10075

bishabosha opened this issue Oct 23, 2020 · 2 comments · Fixed by #18920

Comments

@bishabosha
Copy link
Member

Minimized code

val foo = new PolyFunction {}

Output (click arrow to expand)

Exception in thread "main" java.util.NoSuchElementException: head of empty list
	at scala.collection.immutable.Nil$.head(List.scala:629)
	at scala.collection.immutable.Nil$.head(List.scala:628)
	at dotty.tools.dotc.transform.ElimPolyFunction.functionTypeOfPoly(ElimPolyFunction.scala:48)
	at dotty.tools.dotc.transform.ElimPolyFunction.transform(ElimPolyFunction.scala:34)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:803)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:852)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:823)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:852)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.goForward$1(Denotations.scala:823)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.current(Denotations.scala:852)
	at dotty.tools.dotc.core.Types$NamedType.computeDenot(Types.scala:2043)
	at dotty.tools.dotc.core.Types$NamedType.denot(Types.scala:2006)
	at dotty.tools.dotc.ast.Trees$DenotingTree.denot(Trees.scala:265)
	at dotty.tools.dotc.ast.Trees$Tree.symbol(Trees.scala:154)
	at dotty.tools.dotc.ast.Trees$.dotty$tools$dotc$ast$Trees$Instance$TreeAccumulator$$_$localCtx$2(Trees.scala:1395)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1478)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1511)
	at dotty.tools.dotc.transform.CapturedVars$CollectCaptured.traverse(CapturedVars.scala:69)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1510)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1510)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1385)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1387)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1420)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1511)
	at dotty.tools.dotc.transform.CapturedVars$CollectCaptured.traverse(CapturedVars.scala:69)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1510)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1510)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1475)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1511)
	at dotty.tools.dotc.transform.CapturedVars$CollectCaptured.traverse(CapturedVars.scala:69)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1510)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1510)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1385)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1387)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1482)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1511)
	at dotty.tools.dotc.transform.CapturedVars$CollectCaptured.traverse(CapturedVars.scala:69)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1510)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1510)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1479)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1511)
	at dotty.tools.dotc.transform.CapturedVars$CollectCaptured.traverse(CapturedVars.scala:69)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1510)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.apply(Trees.scala:1510)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.fold$1(Trees.scala:1385)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.apply(Trees.scala:1387)
	at dotty.tools.dotc.ast.Trees$Instance$TreeAccumulator.foldOver(Trees.scala:1486)
	at dotty.tools.dotc.ast.Trees$Instance$TreeTraverser.traverseChildren(Trees.scala:1511)
	at dotty.tools.dotc.transform.CapturedVars$CollectCaptured.traverse(CapturedVars.scala:69)
	at dotty.tools.dotc.transform.CapturedVars$CollectCaptured.runOver(CapturedVars.scala:72)
	at dotty.tools.dotc.transform.CapturedVars.prepareForUnit(CapturedVars.scala:79)
	at dotty.tools.dotc.transform.MegaPhase.prepUnit(MegaPhase.scala:1039)
	at dotty.tools.dotc.transform.MegaPhase.prepUnit(MegaPhase.scala:1039)
	at dotty.tools.dotc.transform.MegaPhase.transformUnit(MegaPhase.scala:446)
	at dotty.tools.dotc.transform.MegaPhase.run(MegaPhase.scala:459)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:296)
	at scala.collection.immutable.List.map(List.scala:246)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:297)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:180)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at dotty.tools.dotc.Run.runPhases$5(Run.scala:190)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:198)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:64)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:205)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:147)
	at dotty.tools.repl.ReplCompiler.runCompilationUnit(ReplCompiler.scala:151)
	at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:161)
	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:233)
	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:196)
	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:129)
	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:132)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:151)
	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:132)
	at dotty.tools.repl.Main$.main(Main.scala:6)
	at dotty.tools.repl.Main.main(Main.scala)
@bishabosha bishabosha changed the title new PolyFunction causes crash at ElimPolyFunction new empty PolyFunction causes crash at ElimPolyFunction Oct 23, 2020
bishabosha added a commit to dotty-staging/dotty that referenced this issue Oct 30, 2020
@bishabosha
Copy link
Member Author

more cases also crash but for different reasons:

val foo = new PolyFunction {} // error
val bar = new PolyFunction { def bar = 23 } // error
val baz = new PolyFunction { def apply = 23 } // error
val qux = new PolyFunction { def apply[T] = 47 } // error

@bishabosha
Copy link
Member Author

@nicolasstucki these still crash, I changed assignment because you made changes to PolyFunction recently

@bishabosha bishabosha changed the title new empty PolyFunction causes crash at ElimPolyFunction user defined anonymous PolyFunction causes crash at ElimPolyFunction Nov 6, 2023
@bishabosha bishabosha changed the title user defined anonymous PolyFunction causes crash at ElimPolyFunction user defined anonymous PolyFunction causes crash at ElimPolyFunction, GenBCode Nov 6, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 14, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 15, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 20, 2023
smarter added a commit that referenced this issue Nov 23, 2023
The `PolyFunction` trait should only be used for compiler generated
encoded lambdas.

Any other use case that was allowed before was accidental. In the
future,
we might consider supporting these if there is a good use case. This
would
probably require a SIP.

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

Successfully merging a pull request may close this issue.

4 participants