Skip to content

Unapply with trivial union type crashes the compiler #8726

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
LPTK opened this issue Apr 15, 2020 · 0 comments · Fixed by #8733
Closed

Unapply with trivial union type crashes the compiler #8726

LPTK opened this issue Apr 15, 2020 · 0 comments · Fixed by #8733

Comments

@LPTK
Copy link
Contributor

LPTK commented Apr 15, 2020

I noticed some strange logic in the handling of unapply return types, so I poked in the REPL a bit and it blew up:

Minimized code

scala> case class A(a: Int)
// defined case class A

scala> object C { def unapply(a: A): true | true = true }
// defined object C

scala> (A(1): A | A) match { case C() => "OK" }
Exception in thread "main" java.lang.AssertionError: assertion failed

Output (click arrow to expand)

Exception in thread "main" java.lang.AssertionError: assertion failed
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:16)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.unapplyPlan$3$$anonfun$2(PatternMatcher.scala:340)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.letAbstract(PatternMatcher.scala:106)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.unapplyPlan$1(PatternMatcher.scala:358)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.patternPlan(PatternMatcher.scala:384)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.caseDefPlan(PatternMatcher.scala:420)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.matchPlan$$anonfun$2$$anonfun$1(PatternMatcher.scala:427)
	at scala.collection.immutable.List.foldRight(List.scala:324)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.matchPlan$$anonfun$1(PatternMatcher.scala:427)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.letAbstract(PatternMatcher.scala:106)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.matchPlan(PatternMatcher.scala:428)
	at dotty.tools.dotc.transform.PatternMatcher$Translator.translateMatch(PatternMatcher.scala:980)
	at dotty.tools.dotc.transform.PatternMatcher.transformMatch(PatternMatcher.scala:41)
	at dotty.tools.dotc.transform.MegaPhase.goMatch(MegaPhase.scala:746)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:345)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
	at dotty.tools.dotc.transform.MegaPhase.mapValDef$1(MegaPhase.scala:234)
	at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:238)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:394)
	at dotty.tools.dotc.transform.MegaPhase.transformStat$2(MegaPhase.scala:404)
	at dotty.tools.dotc.transform.MegaPhase.$anonfun$1(MegaPhase.scala:409)
	at scala.collection.immutable.List.mapConserve(List.scala:444)
	at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:409)
	at dotty.tools.dotc.transform.MegaPhase.transformUnnamed$1(MegaPhase.scala:339)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:396)
	at dotty.tools.dotc.transform.MegaPhase.transformNamed$1(MegaPhase.scala:251)
	at dotty.tools.dotc.transform.MegaPhase.transformTree(MegaPhase.scala:394)
	at dotty.tools.dotc.transform.MegaPhase.transformStat$2(MegaPhase.scala:404)
	at dotty.tools.dotc.transform.MegaPhase.$anonfun$1(MegaPhase.scala:409)
	at scala.collection.immutable.List.mapConserve(List.scala:444)
	at dotty.tools.dotc.transform.MegaPhase.transformStats(MegaPhase.scala:409)
	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:396)
	at dotty.tools.dotc.transform.MegaPhase.transformUnit(MegaPhase.scala:415)
	at dotty.tools.dotc.transform.MegaPhase.run(MegaPhase.scala:427)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:318)
	at scala.collection.immutable.List.map(List.scala:219)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:319)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:165)
	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:175)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:183)
	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:190)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:132)
	at dotty.tools.repl.ReplCompiler.runCompilationUnit(ReplCompiler.scala:156)
	at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:166)
	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:229)
	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:193)
	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:127)
	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:130)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:148)
	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)
@LPTK LPTK changed the title Unapply with Unapply with trivial union type crashes the compiler Apr 15, 2020
@liufengyun liufengyun self-assigned this Apr 15, 2020
liufengyun added a commit to dotty-staging/dotty that referenced this issue Apr 16, 2020
The result type could be `true | true`, subtype check
is much simpler and robust than symbolic check.
liufengyun added a commit that referenced this issue Apr 16, 2020
Fix #8726: test Boolean match with subtype check
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.

2 participants