@@ -3408,19 +3408,28 @@ object Types {
3408
3408
* in Kotlin. A FlexibleType(T) generally behaves like an abstract type with bad bounds
3409
3409
* T|Null .. T, so that T|Null <: FlexibleType(T) <: T.
3410
3410
*/
3411
+ case class FlexibleType (underlying : Type , lo : Type , hi : Type ) extends CachedGroundType with ValueType {
3412
+ def derivedFlexibleType (underlying : Type )(using Context ): Type =
3413
+ if this .underlying eq underlying then this else FlexibleType (underlying)
3414
+
3415
+ override def computeHash (bs : Binders ): Int = doHash(bs, underlying)
3416
+
3417
+ override final def baseClasses (using Context ): List [ClassSymbol ] = underlying.baseClasses
3418
+ }
3411
3419
3412
3420
object FlexibleType {
3413
- def apply (underlying : Type ) = underlying match {
3421
+ def apply (underlying : Type )( using Context ) : FlexibleType = underlying match {
3414
3422
case ft : FlexibleType => ft
3415
- case _ => new FlexibleType (underlying)
3423
+ case _ =>
3424
+ val hi = underlying.stripNull
3425
+ val lo = if hi eq underlying then OrNull (hi) else underlying
3426
+ new FlexibleType (underlying, lo, hi)
3427
+ }
3428
+
3429
+ def unapply (tp : Type )(using Context ): Option [Type ] = tp match {
3430
+ case ft : FlexibleType => Some (ft.underlying)
3431
+ case _ => None
3416
3432
}
3417
- }
3418
- case class FlexibleType (underlying : Type ) extends CachedGroundType with ValueType {
3419
- def lo (using Context ): Type = OrNull (underlying)
3420
- def derivedFlexibleType (under : Type )(using Context ): Type =
3421
- if this .underlying eq under then this else FlexibleType (under)
3422
- override def computeHash (bs : Binders ): Int = doHash(bs, underlying)
3423
- override final def baseClasses (using Context ): List [ClassSymbol ] = underlying.baseClasses
3424
3433
}
3425
3434
3426
3435
// --- AndType/OrType ---------------------------------------------------------------
@@ -5662,8 +5671,8 @@ object Types {
5662
5671
val args1 = args.zipWithConserve(tparams):
5663
5672
case (arg @ TypeBounds (lo, hi), tparam) =>
5664
5673
boundFollowingVariance(lo, hi, tparam)
5665
- case (arg @ FlexibleType (lo, hi) , tparam) =>
5666
- boundFollowingVariance(arg.lo, hi, tparam)
5674
+ case (arg : FlexibleType , tparam) =>
5675
+ boundFollowingVariance(arg.lo, arg. hi, tparam)
5667
5676
case (arg, _) => arg
5668
5677
tp.derivedAppliedType(tycon, args1)
5669
5678
case tp : RefinedType =>
0 commit comments