@@ -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
@@ -2917,8 +2917,9 @@ object Types {
29172917
29182918 def derivedAndOrType (tp1 : Type , tp2 : Type )(using Context ) =
29192919 if ((tp1 eq this .tp1) && (tp2 eq this .tp2)) this
2920- else if (isAnd) AndType .make(tp1, tp2, checkValid = true )
2921- else OrType .make(tp1, tp2)
2920+ else this match
2921+ case tp : OrType => OrType .make(tp1, tp2, tp.isSoft)
2922+ case tp : AndType => AndType .make(tp1, tp2, checkValid = true )
29222923 }
29232924
29242925 abstract case class AndType (tp1 : Type , tp2 : Type ) extends AndOrType {
@@ -2992,6 +2993,7 @@ object Types {
29922993
29932994 abstract case class OrType (tp1 : Type , tp2 : Type ) extends AndOrType {
29942995 def isAnd : Boolean = false
2996+ def isSoft : Boolean
29952997 private var myBaseClassesPeriod : Period = Nowhere
29962998 private var myBaseClasses : List [ClassSymbol ] = _
29972999 /** Base classes of are the intersection of the operand base classes. */
@@ -3054,30 +3056,31 @@ object Types {
30543056
30553057 def derivedOrType (tp1 : Type , tp2 : Type )(using Context ): Type =
30563058 if ((tp1 eq this .tp1) && (tp2 eq this .tp2)) this
3057- else OrType .make(tp1, tp2)
3059+ else OrType .make(tp1, tp2, isSoft )
30583060
3059- override def computeHash (bs : Binders ): Int = doHash(bs, tp1, tp2)
3061+ override def computeHash (bs : Binders ): Int =
3062+ doHash(bs, if isSoft then 0 else 1 , tp1, tp2)
30603063
30613064 override def eql (that : Type ): Boolean = that match {
3062- case that : OrType => tp1.eq(that.tp1) && tp2.eq(that.tp2)
3065+ case that : OrType => tp1.eq(that.tp1) && tp2.eq(that.tp2) && isSoft == that.isSoft
30633066 case _ => false
30643067 }
30653068 }
30663069
3067- final class CachedOrType (tp1 : Type , tp2 : Type ) extends OrType (tp1, tp2)
3070+ final class CachedOrType (tp1 : Type , tp2 : Type , override val isSoft : Boolean ) extends OrType (tp1, tp2)
30683071
30693072 object OrType {
3070- def apply (tp1 : Type , tp2 : Type )(using Context ): OrType = {
3073+ def apply (tp1 : Type , tp2 : Type , soft : Boolean )(using Context ): OrType = {
30713074 assertUnerased()
3072- unique(new CachedOrType (tp1, tp2))
3075+ unique(new CachedOrType (tp1, tp2, soft ))
30733076 }
3074- def make (tp1 : Type , tp2 : Type )(using Context ): Type =
3077+ def make (tp1 : Type , tp2 : Type , soft : Boolean )(using Context ): Type =
30753078 if (tp1 eq tp2) tp1
3076- else apply(tp1, tp2)
3079+ else apply(tp1, tp2, soft )
30773080
30783081 /** Like `make`, but also supports higher-kinded types as argument */
30793082 def makeHk (tp1 : Type , tp2 : Type )(using Context ): Type =
3080- TypeComparer .liftIfHK(tp1, tp2, OrType (_, _), makeHk, _ & _)
3083+ TypeComparer .liftIfHK(tp1, tp2, OrType (_, _, soft = true ), makeHk, _ & _)
30813084 }
30823085
30833086 /** An extractor object to pattern match against a nullable union.
@@ -3089,7 +3092,7 @@ object Types {
30893092 */
30903093 object OrNull {
30913094 def apply (tp : Type )(using Context ) =
3092- OrType (tp, defn.NullType )
3095+ OrType (tp, defn.NullType , soft = false )
30933096 def unapply (tp : Type )(using Context ): Option [Type ] =
30943097 if (ctx.explicitNulls) {
30953098 val tp1 = tp.stripNull()
@@ -3107,7 +3110,7 @@ object Types {
31073110 */
31083111 object OrUncheckedNull {
31093112 def apply (tp : Type )(using Context ) =
3110- OrType (tp, defn.UncheckedNullAliasType )
3113+ OrType (tp, defn.UncheckedNullAliasType , soft = false )
31113114 def unapply (tp : Type )(using Context ): Option [Type ] =
31123115 if (ctx.explicitNulls) {
31133116 val tp1 = tp.stripUncheckedNull
0 commit comments