@@ -282,8 +282,6 @@ object Types {
282
282
tp.bound.derivesFrom(cls) || tp.reduced.derivesFrom(cls)
283
283
case tp : TypeProxy =>
284
284
loop(tp.underlying)
285
- case tp : FlexibleType =>
286
- loop(tp.underlying)
287
285
case tp : AndType =>
288
286
loop(tp.tp1) || loop(tp.tp2)
289
287
case tp : OrType =>
@@ -346,6 +344,7 @@ object Types {
346
344
/** Is this type guaranteed not to have `null` as a value? */
347
345
final def isNotNull (using Context ): Boolean = this match {
348
346
case tp : ConstantType => tp.value.value != null
347
+ case tp : FlexibleType => false
349
348
case tp : ClassInfo => ! tp.cls.isNullableClass && tp.cls != defn.NothingClass
350
349
case tp : AppliedType => tp.superType.isNotNull
351
350
case tp : TypeBounds => tp.lo.isNotNull
@@ -749,8 +748,6 @@ object Types {
749
748
case d : ClassDenotation => d.findMember(name, pre, required, excluded)
750
749
case d => go(d.info)
751
750
}
752
- case tp : FlexibleType =>
753
- go(tp.underlying)
754
751
case tp : AppliedType =>
755
752
tp.tycon match {
756
753
case tc : TypeRef =>
@@ -970,8 +967,6 @@ object Types {
970
967
if (keepOnly(pre, tp.refinedName)) ns + tp.refinedName else ns
971
968
case tp : TypeProxy =>
972
969
tp.superType.memberNames(keepOnly, pre)
973
- case tp : FlexibleType =>
974
- tp.underlying.memberNames(keepOnly, pre)
975
970
case tp : AndType =>
976
971
tp.tp1.memberNames(keepOnly, pre) | tp.tp2.memberNames(keepOnly, pre)
977
972
case tp : OrType =>
@@ -1429,7 +1424,6 @@ object Types {
1429
1424
case tp : ExprType => tp.resType.atoms
1430
1425
case tp : OrType => tp.atoms // `atoms` overridden in OrType
1431
1426
case tp : AndType => tp.tp1.atoms & tp.tp2.atoms
1432
- case tp : FlexibleType => tp.underlying.atoms
1433
1427
case tp : TypeRef if tp.symbol.is(ModuleClass ) =>
1434
1428
// The atom of a module class is the module itself,
1435
1429
// this corresponds to the special case in TypeComparer
@@ -3408,26 +3402,30 @@ object Types {
3408
3402
* in Kotlin. A FlexibleType(T) generally behaves like an abstract type with bad bounds
3409
3403
* T|Null .. T, so that T|Null <: FlexibleType(T) <: T.
3410
3404
*/
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)
3405
+ case class FlexibleType (original : Type , lo : Type , hi : Type ) extends CachedProxyType with ValueType {
3406
+ def underlying (using Context ): Type = original
3414
3407
3415
- override def computeHash ( bs : Binders ): Int = doHash(bs, underlying)
3408
+ override def superType ( using Context ): Type = hi
3416
3409
3417
- override final def baseClasses (using Context ): List [ClassSymbol ] = underlying.baseClasses
3410
+ def derivedFlexibleType (original : Type )(using Context ): Type =
3411
+ if this .original eq original then this else FlexibleType (original)
3412
+
3413
+ override def computeHash (bs : Binders ): Int = doHash(bs, original)
3414
+
3415
+ override final def baseClasses (using Context ): List [ClassSymbol ] = original.baseClasses
3418
3416
}
3419
3417
3420
3418
object FlexibleType {
3421
- def apply (underlying : Type )(using Context ): FlexibleType = underlying match {
3419
+ def apply (original : Type )(using Context ): FlexibleType = original match {
3422
3420
case ft : FlexibleType => ft
3423
3421
case _ =>
3424
- val hi = underlying .stripNull
3425
- val lo = if hi eq underlying then OrNull (hi) else underlying
3426
- new FlexibleType (underlying , lo, hi)
3422
+ val hi = original .stripNull
3423
+ val lo = if hi eq original then OrNull (hi) else original
3424
+ new FlexibleType (original , lo, hi)
3427
3425
}
3428
3426
3429
3427
def unapply (tp : Type )(using Context ): Option [Type ] = tp match {
3430
- case ft : FlexibleType => Some (ft.underlying )
3428
+ case ft : FlexibleType => Some (ft.original )
3431
3429
case _ => None
3432
3430
}
3433
3431
}
@@ -5671,6 +5669,7 @@ object Types {
5671
5669
val args1 = args.zipWithConserve(tparams):
5672
5670
case (arg @ TypeBounds (lo, hi), tparam) =>
5673
5671
boundFollowingVariance(lo, hi, tparam)
5672
+ // TODO: why do we need this?
5674
5673
case (arg : FlexibleType , tparam) =>
5675
5674
boundFollowingVariance(arg.lo, arg.hi, tparam)
5676
5675
case (arg, _) => arg
@@ -5709,7 +5708,7 @@ object Types {
5709
5708
case tp : AnnotatedType =>
5710
5709
samClass(tp.underlying)
5711
5710
case tp : FlexibleType =>
5712
- samClass(tp.underlying )
5711
+ samClass(tp.superType )
5713
5712
case _ =>
5714
5713
NoSymbol
5715
5714
0 commit comments