-
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
Pattern matching on a sealed trait
extended by its child leads to stack overflow and crash
#19031
Comments
sealed trait
extended by its child leads to stack overflow and crash
To add a small thing: note that the following is indeed a complete pattern match: def compute(a: A): Boolean =
a match
case inductive: A#B => ???
case base: A => ??? It seems to me that the difference of types may be computed incorrectly here? Leading to what looks like the type Hope this helps |
After bisect: Will continue looking, I think it may be a bit more complex. |
Are you able to update LISA now? |
Thanks for the very quick response, I had been following some of the discussion on the PR. I am attempting to compile LISA with dotty main, but I ran into some trouble with my little example before, which may be worth a look: The base example I posted above works now (thanks!): sealed trait A:
class B extends A
def compute(a: A): Boolean =
a match
case b: A#B => true But adding a single line base case can lend you a crash again: sealed trait A:
class B extends A
class C extends A // <== base case
def compute(a: A): Boolean =
a match
case b: A#B => true
Running via > run /tmp/sctest/Sealed.scala
[info] running (fork) dotty.tools.dotc.Main -d /home/sankalp/projects/scala-spree/dotty-working/compiler/../out/default-last-scalac-out.jar -classpath /home/sankalp/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar:/home/sankalp/projects/scala-spree/dotty-working/library/../out/bootstrap/scala3-library-bootstrapped/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala3-library_3-3.4.0-RC1-bin-SNAPSHOT.jar /tmp/sctest/Sealed.scala
Exception in thread "main" java.lang.StackOverflowError
unhandled exception while running MegaPhase{protectedAccessors, extmethods, uncacheGivenAliases, elimByName, hoistSuperArgs, forwardDepChecks, specializeApplyMethods, tryCatchPatterns, patternMatcher} on /tmp/sctest/Sealed.scala
An unhandled exception was thrown in the compiler.
Please file a crash report here:
https://github.com/lampepfl/dotty/issues/new/choose
For non-enriched exceptions, compile with -Yno-enrich-error-messages.
while compiling: /tmp/sctest/Sealed.scala
during phase: MegaPhase{protectedAccessors, extmethods, uncacheGivenAliases, elimByName, hoistSuperArgs, forwardDepChecks, specializeApplyMethods, tryCatchPatterns, patternMatcher}
mode: Mode(ImplicitsEnabled)
library version: version 2.13.12
compiler version: version 3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped-git-8d9da73
settings: -classpath /home/sankalp/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar:/home/sankalp/projects/scala-spree/dotty-working/library/../out/bootstrap/scala3-library-bootstrapped/scala-3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala3-library_3-3.4.0-RC1-bin-SNAPSHOT.jar -d /
at dotty.tools.dotc.core.Types$LambdaType.paramRefs(Types.scala:3743)
at dotty.tools.dotc.core.Types$LambdaType.paramRefs$(Types.scala:3720)
at dotty.tools.dotc.core.Types$MethodOrPoly.paramRefs(Types.scala:3804)
at dotty.tools.dotc.core.OrderingConstraint.adjustDeps$$anonfun$2(OrderingConstraint.scala:433)
at dotty.tools.dotc.core.OrderingConstraint.adjustDeps$$anonfun$adapted$1(OrderingConstraint.scala:434)
at scala.collection.immutable.Range.foreach(Range.scala:190)
at dotty.tools.dotc.core.OrderingConstraint.adjustDeps(OrderingConstraint.scala:434)
at dotty.tools.dotc.core.OrderingConstraint.init(OrderingConstraint.scala:537)
at dotty.tools.dotc.core.OrderingConstraint.add(OrderingConstraint.scala:515)
at dotty.tools.dotc.core.OrderingConstraint.add(OrderingConstraint.scala:508)
at dotty.tools.dotc.core.ConstraintHandling.addToConstraint(ConstraintHandling.scala:761)
at dotty.tools.dotc.core.ConstraintHandling.addToConstraint$(ConstraintHandling.scala:29)
at dotty.tools.dotc.core.TypeComparer.addToConstraint(TypeComparer.scala:30)
at dotty.tools.dotc.core.TypeComparer$.addToConstraint(TypeComparer.scala:3217)
at dotty.tools.dotc.typer.ProtoTypes$.constrained(ProtoTypes.scala:746)
at dotty.tools.dotc.typer.ProtoTypes$.newTypeVar(ProtoTypes.scala:779)
at dotty.tools.dotc.core.TypeOps$InferPrefixMap$1.apply(TypeOps.scala:896)
at dotty.tools.dotc.core.Types$TypeMap.op$proxy18$1(Types.scala:6056)
at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:6056)
at dotty.tools.dotc.core.TypeOps$InferPrefixMap$1.apply(TypeOps.scala:899)
at dotty.tools.dotc.core.TypeOps$.instantiateToSubType(TypeOps.scala:905)
at dotty.tools.dotc.core.TypeOps$.refineUsingParent(TypeOps.scala:757)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.$anonfun$13(Space.scala:648)
at scala.collection.immutable.List.map(List.scala:246)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.rec$1(Space.scala:659)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.decompose(Space.scala:667)
at dotty.tools.dotc.transform.patmat.SpaceEngine$Parts$.unapply(Space.scala:687)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.rec$1(Space.scala:622)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.decompose(Space.scala:667)
at dotty.tools.dotc.transform.patmat.SpaceEngine$Parts$.unapply(Space.scala:687)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.rec$1(Space.scala:622)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.decompose(Space.scala:667)
at dotty.tools.dotc.transform.patmat.SpaceEngine$Parts$.unapply(Space.scala:687)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.rec$1(Space.scala:622)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.decompose(Space.scala:667)
at dotty.tools.dotc.transform.patmat.SpaceEngine$Parts$.unapply(Space.scala:687)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.rec$1(Space.scala:622)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.decompose(Space.scala:667)
at dotty.tools.dotc.transform.patmat.SpaceEngine$Parts$.unapply(Space.scala:687)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.rec$1(Space.scala:622)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.decompose(Space.scala:667)
at dotty.tools.dotc.transform.patmat.SpaceEngine$Parts$.unapply(Space.scala:687)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.rec$1(Space.scala:622)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.decompose(Space.scala:667)
at dotty.tools.dotc.transform.patmat.SpaceEngine$Parts$.unapply(Space.scala:687)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.rec$1(Space.scala:622)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.decompose(Space.scala:667)
at dotty.tools.dotc.transform.patmat.SpaceEngine$Parts$.unapply(Space.scala:687)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.rec$1(Space.scala:622)
at dotty.tools.dotc.transform.patmat.SpaceEngine$.decompose(Space.scala:667)
<STACK TRACE TRIMMED BY AUTHOR> |
We have a similar base case in LISA as well :( Setting the scala version in sbt to the nightly from maven: 3.4.0-RC1-bin-20231218-ec2b8bc-NIGHTLY I get a similar crash while compiling LISA as well. The base case was not necessary to reproduce the crash before, so I did not think of including it in my minimal example for this issue, sorry about that. |
Do you mind if I reopen the issue, @Decel, or would it be better to create a separate one? |
Compiler version
main: 3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped-git-c90ad6b
3.3.1
originally discovered on 3.3.1, used main for isolation and for the logs below
HOWEVER, works on 3.2.2
Minimized code
Output (click arrow to expand)
With 3.4.0-RC1-bin-SNAPSHOT-nonbootstrapped-git-c90ad6b (failing):
Identical output for 3.3.1
With 3.2.2 (working):
Source and Problem
Discovered as epfl-lara/lisa#190, where we are unable to upgrade from 3.2.2, where this does work, to 3.3.1 as we would like to.
The text was updated successfully, but these errors were encountered: