@@ -1040,7 +1040,7 @@ object Types {
10401040 def safe_& (that : Type )(using Context ): Type = (this , that) match {
10411041 case (TypeBounds (lo1, hi1), TypeBounds (lo2, hi2)) =>
10421042 TypeBounds (
1043- OrType .makeHk(lo1.stripLazyRef, lo2.stripLazyRef),
1043+ OrType .makeHk(lo1.stripLazyRef, lo2.stripLazyRef),
10441044 AndType .makeHk(hi1.stripLazyRef, hi2.stripLazyRef))
10451045 case _ =>
10461046 this & that
@@ -2907,8 +2907,9 @@ object Types {
29072907
29082908 def derivedAndOrType (tp1 : Type , tp2 : Type )(using Context ) =
29092909 if ((tp1 eq this .tp1) && (tp2 eq this .tp2)) this
2910- else if (isAnd) AndType .make(tp1, tp2, checkValid = true )
2911- else OrType .make(tp1, tp2)
2910+ else this match
2911+ case tp : OrType => OrType .make(tp1, tp2, tp.isSoft)
2912+ case tp : AndType => AndType .make(tp1, tp2, checkValid = true )
29122913 }
29132914
29142915 abstract case class AndType (tp1 : Type , tp2 : Type ) extends AndOrType {
@@ -2982,6 +2983,7 @@ object Types {
29822983
29832984 abstract case class OrType (tp1 : Type , tp2 : Type ) extends AndOrType {
29842985 def isAnd : Boolean = false
2986+ def isSoft : Boolean
29852987 private var myBaseClassesPeriod : Period = Nowhere
29862988 private var myBaseClasses : List [ClassSymbol ] = _
29872989 /** Base classes of are the intersection of the operand base classes. */
@@ -3044,30 +3046,31 @@ object Types {
30443046
30453047 def derivedOrType (tp1 : Type , tp2 : Type )(using Context ): Type =
30463048 if ((tp1 eq this .tp1) && (tp2 eq this .tp2)) this
3047- else OrType .make(tp1, tp2)
3049+ else OrType .make(tp1, tp2, isSoft )
30483050
3049- override def computeHash (bs : Binders ): Int = doHash(bs, tp1, tp2)
3051+ override def computeHash (bs : Binders ): Int =
3052+ doHash(bs, if isSoft then 0 else 1 , tp1, tp2)
30503053
30513054 override def eql (that : Type ): Boolean = that match {
3052- case that : OrType => tp1.eq(that.tp1) && tp2.eq(that.tp2)
3055+ case that : OrType => tp1.eq(that.tp1) && tp2.eq(that.tp2) && isSoft == that.isSoft
30533056 case _ => false
30543057 }
30553058 }
30563059
3057- final class CachedOrType (tp1 : Type , tp2 : Type ) extends OrType (tp1, tp2)
3060+ final class CachedOrType (tp1 : Type , tp2 : Type , override val isSoft : Boolean ) extends OrType (tp1, tp2)
30583061
30593062 object OrType {
3060- def apply (tp1 : Type , tp2 : Type )(using Context ): OrType = {
3063+ def apply (tp1 : Type , tp2 : Type , soft : Boolean )(using Context ): OrType = {
30613064 assertUnerased()
3062- unique(new CachedOrType (tp1, tp2))
3065+ unique(new CachedOrType (tp1, tp2, soft ))
30633066 }
3064- def make (tp1 : Type , tp2 : Type )(using Context ): Type =
3067+ def make (tp1 : Type , tp2 : Type , soft : Boolean )(using Context ): Type =
30653068 if (tp1 eq tp2) tp1
3066- else apply(tp1, tp2)
3069+ else apply(tp1, tp2, soft )
30673070
30683071 /** Like `make`, but also supports higher-kinded types as argument */
30693072 def makeHk (tp1 : Type , tp2 : Type )(using Context ): Type =
3070- TypeComparer .liftIfHK(tp1, tp2, OrType (_, _), makeHk, _ & _)
3073+ TypeComparer .liftIfHK(tp1, tp2, OrType (_, _, soft = true ), makeHk, _ & _)
30713074 }
30723075
30733076 /** An extractor object to pattern match against a nullable union.
@@ -3079,7 +3082,7 @@ object Types {
30793082 */
30803083 object OrNull {
30813084 def apply (tp : Type )(using Context ) =
3082- OrType (tp, defn.NullType )
3085+ OrType (tp, defn.NullType , soft = false )
30833086 def unapply (tp : Type )(using Context ): Option [Type ] =
30843087 if (ctx.explicitNulls) {
30853088 val tp1 = tp.stripNull()
@@ -3097,7 +3100,7 @@ object Types {
30973100 */
30983101 object OrUncheckedNull {
30993102 def apply (tp : Type )(using Context ) =
3100- OrType (tp, defn.UncheckedNullAliasType )
3103+ OrType (tp, defn.UncheckedNullAliasType , soft = false )
31013104 def unapply (tp : Type )(using Context ): Option [Type ] =
31023105 if (ctx.explicitNulls) {
31033106 val tp1 = tp.stripUncheckedNull
0 commit comments