Skip to content

Commit

Permalink
Fix handling of baseType of (A & Double) | Null
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Oct 24, 2022
1 parent d9301e0 commit 754b68e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ object TypeOps:
}

// Step 3: Intersect base classes of both sides
val commonBaseClasses = tp.mapReduceOr(_.baseClasses)(intersect)
val commonBaseClasses = tp.mapReduceAndOr(_.baseClasses)(intersect)
val doms = dominators(commonBaseClasses, Nil)
def baseTp(cls: ClassSymbol): Type =
tp.baseType(cls).mapReduceOr(identity)(mergeRefinedOrApplied)
Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ object Types {
case _ => f(this)
}

final def mapReduceAndOr[T](f: Type => T)(g: (T, T) => T)(using Context): T = stripTypeVar match {
case tp: AndOrType => g(tp.tp1.mapReduceAndOr(f)(g), tp.tp2.mapReduceAndOr(f)(g))
case _ => f(this)
}

// ----- Associated symbols ----------------------------------------------

/** The type symbol associated with the type */
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i16236.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
trait A

def consume[T](t: T): Unit = ()

def fails(p: (Double & A) | Null): Unit = consume(p) // was: assertion failed: <notype> & A

def switchedOrder(p: (A & Double) | Null): Unit = consume(p) // ok
def nonPrimitive(p: (String & A) | Null): Unit = consume(p) // ok
def notNull(p: (Double & A)): Unit = consume(p) // ok

0 comments on commit 754b68e

Please sign in to comment.