Skip to content

Commit 754b68e

Browse files
committed
Fix handling of baseType of (A & Double) | Null
1 parent d9301e0 commit 754b68e

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-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
@@ -369,7 +369,7 @@ object TypeOps:
369369
}
370370

371371
// Step 3: Intersect base classes of both sides
372-
val commonBaseClasses = tp.mapReduceOr(_.baseClasses)(intersect)
372+
val commonBaseClasses = tp.mapReduceAndOr(_.baseClasses)(intersect)
373373
val doms = dominators(commonBaseClasses, Nil)
374374
def baseTp(cls: ClassSymbol): Type =
375375
tp.baseType(cls).mapReduceOr(identity)(mergeRefinedOrApplied)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,11 @@ object Types {
478478
case _ => f(this)
479479
}
480480

481+
final def mapReduceAndOr[T](f: Type => T)(g: (T, T) => T)(using Context): T = stripTypeVar match {
482+
case tp: AndOrType => g(tp.tp1.mapReduceAndOr(f)(g), tp.tp2.mapReduceAndOr(f)(g))
483+
case _ => f(this)
484+
}
485+
481486
// ----- Associated symbols ----------------------------------------------
482487

483488
/** The type symbol associated with the type */

tests/pos/i16236.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait A
2+
3+
def consume[T](t: T): Unit = ()
4+
5+
def fails(p: (Double & A) | Null): Unit = consume(p) // was: assertion failed: <notype> & A
6+
7+
def switchedOrder(p: (A & Double) | Null): Unit = consume(p) // ok
8+
def nonPrimitive(p: (String & A) | Null): Unit = consume(p) // ok
9+
def notNull(p: (Double & A)): Unit = consume(p) // ok

0 commit comments

Comments
 (0)