Skip to content

Commit c0db02c

Browse files
committed
Harden orDominator
Fixes #13435
1 parent b81f50f commit c0db02c

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,11 @@ object TypeOps:
349349
val doms = dominators(commonBaseClasses, Nil)
350350
def baseTp(cls: ClassSymbol): Type =
351351
tp.baseType(cls).mapReduceOr(identity)(mergeRefinedOrApplied)
352-
doms.map(baseTp).reduceLeft(AndType.apply)
352+
def meet(tp1: Type, tp2: Type) =
353+
if !tp1.exists then tp2
354+
else if !tp2.exists then tp1
355+
else AndType(tp1, tp2)
356+
doms.map(baseTp).reduceLeft(meet)
353357
}
354358

355359
tp match {

tests/neg/i13435.check

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- [E029] Pattern Match Exhaustivity Warning: tests/neg/i13435.scala:7:2 -----------------------------------------------
2+
7 | s match
3+
| ^
4+
| match may not be exhaustive.
5+
|
6+
| It would fail on pattern case: (_), ((_, _), (_, _))
7+
8+
longer explanation available when compiling with `-explain`
9+
-- Error: tests/neg/i13435.scala:8:10 ----------------------------------------------------------------------------------
10+
8 | case (dim: Axis, size: Int) => dim // error
11+
| ^^^^^^^^^
12+
| trait Singleton cannot be used in runtime type tests

tests/neg/i13435.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
type Axis = String&Singleton
2+
type ShapeTuple = Tuple1[(Axis, Int)]|Tuple2[(Axis, Int), (Axis, Int)]
3+
type Shape = (Axis, Int) |ShapeTuple
4+
5+
6+
def mkSchema(s: Shape) =
7+
s match
8+
case (dim: Axis, size: Int) => dim // error

0 commit comments

Comments
 (0)