Skip to content

Commit d58b14f

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

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ 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+
doms.map(baseTp).filter(_.exists).reduceLeft(AndType.apply)
353353
}
354354

355355
tp match {

tests/neg/i13435.check

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class sym (Axis, Int) | ShapeTuple
2+
class sym Int *: EmptyTuple.type | (EmptyTuple.type | (Axis, Int) *: EmptyTuple.type)
3+
approx or Int *: EmptyTuple.type | (EmptyTuple.type | (Axis, Int) *: EmptyTuple.type)///trait Tuple/// Tuple
4+
approx or (Axis, Int) | ShapeTuple///trait Product2, trait Serializable, class *:/// <notype>, Serializable, (Axis | (Axis, Int)) *: (Int *: EmptyTuple.type | (EmptyTuple.type | (Axis, Int)
5+
6+
*: EmptyTuple.type))
7+
class sym Tuple1[(Axis, Int)] | ((Axis, Int), (Axis, Int))
8+
class sym EmptyTuple.type | (Axis, Int) *: EmptyTuple.type
9+
approx or EmptyTuple | (Axis, Int) *: EmptyTuple.type///trait Tuple/// Tuple
10+
approx or Tuple1[(Axis, Int)] | ((Axis, Int), (Axis, Int))///trait Serializable, class *:/// Serializable, (Axis, Int) *: (EmptyTuple.type | (Axis, Int) *: EmptyTuple.type)
11+
-- [E029] Pattern Match Exhaustivity Warning: i13435.scala:7:2 -----------------
12+
7 | s match
13+
| ^
14+
| match may not be exhaustive.
15+
|
16+
| It would fail on pattern case: (_), ((_, _), (_, _))
17+
18+
longer explanation available when compiling with `-explain`
19+
class sym (Axis, Int) | ShapeTuple
20+
class sym Tuple1[(Axis, Int)] | ((Axis, Int), (Axis, Int))
21+
class sym (Axis, Int) | ShapeTuple
22+
class sym Int *: EmptyTuple.type | (EmptyTuple.type | (Axis, Int) *: EmptyTuple.type)
23+
approx or Int *: EmptyTuple.type | (EmptyTuple.type | (Axis, Int) *: EmptyTuple.type)///trait Tuple/// Tuple
24+
approx or (Axis, Int) | ShapeTuple///trait Product2, trait Serializable, class *:/// <notype>, Serializable, (Axis | (Axis, Int)) *: (Int *: EmptyTuple.type | (EmptyTuple.type | (Axis, Int)
25+
26+
*: EmptyTuple.type))
27+
-- Error: i13435.scala:8:10 ----------------------------------------------------
28+
8 | case (dim: Axis, size: Int) => dim // error
29+
| ^^^^^^^^^
30+
| trait Singleton cannot be used in runtime type tests
31+
1 warning found
32+
1 error found

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)