Skip to content

Commit c1dfcef

Browse files
dwijnandWojciechMazur
authored andcommitted
Remove unnecessary and recursive Space decomposition
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. [Cherry-picked 5439e98]
1 parent 208a728 commit c1dfcef

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Diff for: compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

-4
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,13 @@ object SpaceEngine {
209209
case (a @ Typ(tp1, _), b @ Typ(tp2, _)) =>
210210
if isSubType(tp1, tp2) then a
211211
else if isSubType(tp2, tp1) then b
212-
else if canDecompose(a) then intersect(Or(decompose(a)), b)
213-
else if canDecompose(b) then intersect(a, Or(decompose(b)))
214212
else intersectUnrelatedAtomicTypes(tp1, tp2)(a)
215213
case (a @ Typ(tp1, _), Prod(tp2, fun, ss)) =>
216214
if isSubType(tp2, tp1) then b
217-
else if canDecompose(a) then intersect(Or(decompose(a)), b)
218215
else if isSubType(tp1, tp2) then a // problematic corner case: inheriting a case class
219216
else intersectUnrelatedAtomicTypes(tp1, tp2)(b)
220217
case (Prod(tp1, fun, ss), b @ Typ(tp2, _)) =>
221218
if isSubType(tp1, tp2) then a
222-
else if canDecompose(b) then intersect(a, Or(decompose(b)))
223219
else if isSubType(tp2, tp1) then a // problematic corner case: inheriting a case class
224220
else intersectUnrelatedAtomicTypes(tp1, tp2)(a)
225221
case (a @ Prod(tp1, fun1, ss1), Prod(tp2, fun2, ss2)) =>

Diff for: tests/pos/i19031.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//> using options -Werror
2+
3+
sealed trait A:
4+
class B extends A
5+
6+
class Test:
7+
def t1(a: A): Boolean =
8+
a match
9+
case b: A#B => true

0 commit comments

Comments
 (0)