From e167c64f33fcd5b88581c65d14aaa96228f4dd65 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 6 Dec 2023 18:04:27 +0000 Subject: [PATCH] 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. --- .../src/dotty/tools/dotc/transform/patmat/Space.scala | 4 ---- tests/pos/i19031.scala | 9 +++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 tests/pos/i19031.scala diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index beb4119775d0..2c195e851261 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -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)) => diff --git a/tests/pos/i19031.scala b/tests/pos/i19031.scala new file mode 100644 index 000000000000..e56744017255 --- /dev/null +++ b/tests/pos/i19031.scala @@ -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