Skip to content

Commit

Permalink
Fix #12559: Try decomposable types in isSubspace
Browse files Browse the repository at this point in the history
  • Loading branch information
liufengyun committed May 25, 2021
1 parent 9b4be14 commit 9a0182a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ trait SpaceLogic {
ss.forall(isSubspace(_, b))
case (Typ(tp1, _), Typ(tp2, _)) =>
isSubType(tp1, tp2)
|| canDecompose(tp1) && tryDecompose1(tp1)
|| canDecompose(tp2) && tryDecompose2(tp2)
case (Typ(tp1, _), Or(ss)) => // optimization: don't go to subtraction too early
ss.exists(isSubspace(a, _)) || tryDecompose1(tp1)
case (_, Or(_)) =>
Expand Down
2 changes: 2 additions & 0 deletions tests/patmat/i12559.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
10: Match case Unreachable
27: Match case Unreachable
35 changes: 35 additions & 0 deletions tests/patmat/i12559.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package akka.event

object TestA:
sealed trait LogEvent

object LogEvent:
def myOrdinal(e: LogEvent): Int = e match
case e: Error => 0
// case e: Warning => 1
case e: LogEventWithMarker => 2


class Error() extends LogEvent
class Error2() extends Error() with LogEventWithMarker

// case class Warning() extends LogEvent

sealed trait LogEventWithMarker extends LogEvent

object TestB:
sealed trait LogEvent

object LogEvent:
def myOrdinal(e: LogEvent): Int = e match
case e: Error => 0
case e: Warning => 1
case e: LogEventWithMarker => 2


case class Error() extends LogEvent
class Error2() extends Error() with LogEventWithMarker

case class Warning() extends LogEvent

sealed trait LogEventWithMarker extends LogEvent

0 comments on commit 9a0182a

Please sign in to comment.