-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Compiler crashes in ExpandSAMs phase #15855
Comments
KacperFKorban
added a commit
to dotty-staging/dotty
that referenced
this issue
Aug 25, 2022
Expanding a SAM into an anonymous class assumes that the parent class has a constructor with empty paramerer list. Before this change, a situation in which there was no such constructor caused a crash. fixes scala#15855
KacperFKorban
added a commit
to dotty-staging/dotty
that referenced
this issue
Aug 25, 2022
Expanding a SAM into an anonymous class assumes that the parent class has a constructor with an empty parameter list. Before this change, a situation in which there was no such constructor caused a crash. fixes scala#15855
KacperFKorban
referenced
this issue
in dotty-staging/dotty
Sep 1, 2022
Previously creating ClassDefs of AnonClasses was only possible if the parent class had a constructor wih an empty parameter list. Otherwise the compiler would crash becasue of calling `asTerm` on a `NoSymbol`. This PR adds logic that handles callig parent constructors with default or repeated parameters. And also fails more gracefuly if no instance can be created. fixes lampepfl#15855
KacperFKorban
referenced
this issue
in dotty-staging/dotty
Sep 1, 2022
Previously creating ClassDefs of AnonClasses was only possible if the parent class had a constructor with an empty parameter list. Otherwise, the compiler would crash because of calling `asTerm` on a `NoSymbol`. This PR adds logic that handles calling parent constructors with default or repeated parameters. And also fails more gracefully if no instance can be created. fixes lampepfl#15855 (attempt 2)
I believe I got another instance of this issue: ➜ ~/scala-sam-bug cat test2.scala //> using dep org.scala-js::scalajs-dom_sjs1:2.8.0
import org.scalajs.dom.document
@main def test2 = document.getElementById("foo").addEventListener("input", _ => ???) ➜ ~/scala-sam-bug scala-cli compile test2.scala
Compiling project (Scala 3.3.1, JVM (17))
Error compiling project (Scala 3.3.1, JVM (17))
Error: Unexpected error when compiling scala-sam-bug_035d174876-089f72375e: java.lang.AssertionError: assertion failed: asTerm called on not-a-Term val <none>
at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
at dotty.tools.dotc.core.Symbols$Symbol.asTerm(Symbols.scala:169)
at dotty.tools.dotc.ast.tpd$.ClassDef(tpd.scala:324)
at dotty.tools.dotc.ast.tpd$.AnonClass(tpd.scala:385)
at dotty.tools.dotc.ast.tpd$.AnonClass(tpd.scala:367)
at dotty.tools.dotc.transform.ExpandSAMs.transformBlock(ExpandSAMs.scala:63)
at dotty.tools.dotc.transform.MegaPhase.goBlock(MegaPhase.scala:759)
at dotty.tools.dotc.transform.MegaPhase.goBlock(MegaPhase.scala:760)
at dotty.tools.dotc.transform.MegaPhase.transformBlock(MegaPhase.scala:465)
at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:303)
at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:442)
at dotty.tools.dotc.transform.MegaPhase.loop$3(MegaPhase.scala:474)
... Note: this works when compiled for Scala.js:
Note 2: this works on the JVM: //> using dep org.scala-js::scalajs-dom_sjs1:2.8.0
import org.scalajs.dom.{document, Event}
import scala.scalajs.js.Function1
@main def test2 = document.getElementById("foo").addEventListener("input", new Function1[Event, Unit] {
def apply(e: Event) = ???
}) @sjrd explained to me that |
odersky
added a commit
that referenced
this issue
Sep 18, 2024
The first two fixes concern characterization of SAM types. One condition of a SAM type is that it can be instantiated with an empty argument list. This was implemented incorrectly. First, we missed the case where the SAM type is a trait with a parent class that takes arguments. In this case the SAM type _cannot_ be instantiated with an empty argument list. Second, we missed the case where the SAM type constructor has a single vararg parameter. In this case the SAM type _can_ be instantiated with an empty argument list. The second case was also translated incorrectly which led to illegal bytecodes. Fixes #15855
WojciechMazur
pushed a commit
that referenced
this issue
Dec 3, 2024
The first two fixes concern characterization of SAM types. One condition of a SAM type is that it can be instantiated with an empty argument list. This was implemented incorrectly. First, we missed the case where the SAM type is a trait with a parent class that takes arguments. In this case the SAM type _cannot_ be instantiated with an empty argument list. Second, we missed the case where the SAM type constructor has a single vararg parameter. In this case the SAM type _can_ be instantiated with an empty argument list. The second case was also translated incorrectly which led to illegal bytecodes. Fixes #15855 [Cherry-picked f0b6763]
WojciechMazur
pushed a commit
that referenced
this issue
Dec 3, 2024
The first two fixes concern characterization of SAM types. One condition of a SAM type is that it can be instantiated with an empty argument list. This was implemented incorrectly. First, we missed the case where the SAM type is a trait with a parent class that takes arguments. In this case the SAM type _cannot_ be instantiated with an empty argument list. Second, we missed the case where the SAM type constructor has a single vararg parameter. In this case the SAM type _can_ be instantiated with an empty argument list. The second case was also translated incorrectly which led to illegal bytecodes. Fixes #15855 [Cherry-picked f0b6763]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiler version
Minimized code
Output
Expectation
dotc doesn't crash.
Notes
The text was updated successfully, but these errors were encountered: