Skip to content

Commit

Permalink
Remove unnecessary and recursive Space decomposition
Browse files Browse the repository at this point in the history
Space decomposition recently learnt to decompose prefixes.  Given a
nested definition like in i19031, aggressively trying to decompose while
intersecting can lead to recursive decompositions (building bigger and
bigger nested prefixes).  Turns out the decomposition isn't necessary.
  • Loading branch information
dwijnand committed Dec 6, 2023
1 parent d96e9e4 commit e167c64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 0 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,13 @@ object SpaceEngine {
case (a @ Typ(tp1, _), b @ Typ(tp2, _)) =>
if isSubType(tp1, tp2) then a
else if isSubType(tp2, tp1) then b
else if canDecompose(a) then intersect(Or(decompose(a)), b)
else if canDecompose(b) then intersect(a, Or(decompose(b)))
else intersectUnrelatedAtomicTypes(tp1, tp2)(a)
case (a @ Typ(tp1, _), Prod(tp2, fun, ss)) =>
if isSubType(tp2, tp1) then b
else if canDecompose(a) then intersect(Or(decompose(a)), b)
else if isSubType(tp1, tp2) then a // problematic corner case: inheriting a case class
else intersectUnrelatedAtomicTypes(tp1, tp2)(b)
case (Prod(tp1, fun, ss), b @ Typ(tp2, _)) =>
if isSubType(tp1, tp2) then a
else if canDecompose(b) then intersect(a, Or(decompose(b)))
else if isSubType(tp2, tp1) then a // problematic corner case: inheriting a case class
else intersectUnrelatedAtomicTypes(tp1, tp2)(a)
case (a @ Prod(tp1, fun1, ss1), Prod(tp2, fun2, ss2)) =>
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i19031.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//> using options -Werror

sealed trait A:
class B extends A

class Test:
def t1(a: A): Boolean =
a match
case b: A#B => true

0 comments on commit e167c64

Please sign in to comment.