@@ -281,8 +281,6 @@ object Types extends TypeUtils {
281
281
tp.bound.derivesFrom(cls) || tp.reduced.derivesFrom(cls)
282
282
case tp : TypeProxy =>
283
283
loop(tp.underlying)
284
- case tp : FlexibleType =>
285
- loop(tp.underlying)
286
284
case tp : AndType =>
287
285
loop(tp.tp1) || loop(tp.tp2)
288
286
case tp : OrType =>
@@ -345,6 +343,7 @@ object Types extends TypeUtils {
345
343
/** Is this type guaranteed not to have `null` as a value? */
346
344
final def isNotNull (using Context ): Boolean = this match {
347
345
case tp : ConstantType => tp.value.value != null
346
+ case tp : FlexibleType => false
348
347
case tp : ClassInfo => ! tp.cls.isNullableClass && tp.cls != defn.NothingClass
349
348
case tp : AppliedType => tp.superType.isNotNull
350
349
case tp : TypeBounds => tp.lo.isNotNull
@@ -754,8 +753,6 @@ object Types extends TypeUtils {
754
753
case d : ClassDenotation => d.findMember(name, pre, required, excluded)
755
754
case d => go(d.info)
756
755
}
757
- case tp : FlexibleType =>
758
- go(tp.underlying)
759
756
case tp : AppliedType =>
760
757
tp.tycon match {
761
758
case tc : TypeRef =>
@@ -968,8 +965,6 @@ object Types extends TypeUtils {
968
965
if (keepOnly(pre, tp.refinedName)) ns + tp.refinedName else ns
969
966
case tp : TypeProxy =>
970
967
tp.superType.memberNames(keepOnly, pre)
971
- case tp : FlexibleType =>
972
- tp.underlying.memberNames(keepOnly, pre)
973
968
case tp : AndType =>
974
969
tp.tp1.memberNames(keepOnly, pre) | tp.tp2.memberNames(keepOnly, pre)
975
970
case tp : OrType =>
@@ -1427,7 +1422,6 @@ object Types extends TypeUtils {
1427
1422
case tp : ExprType => tp.resType.atoms
1428
1423
case tp : OrType => tp.atoms // `atoms` overridden in OrType
1429
1424
case tp : AndType => tp.tp1.atoms & tp.tp2.atoms
1430
- case tp : FlexibleType => tp.underlying.atoms
1431
1425
case tp : TypeRef if tp.symbol.is(ModuleClass ) =>
1432
1426
// The atom of a module class is the module itself,
1433
1427
// this corresponds to the special case in TypeComparer
@@ -3410,26 +3404,30 @@ object Types extends TypeUtils {
3410
3404
* in Kotlin. A FlexibleType(T) generally behaves like an abstract type with bad bounds
3411
3405
* T|Null .. T, so that T|Null <: FlexibleType(T) <: T.
3412
3406
*/
3413
- case class FlexibleType (underlying : Type , lo : Type , hi : Type ) extends CachedGroundType with ValueType {
3414
- def derivedFlexibleType (underlying : Type )(using Context ): Type =
3415
- if this .underlying eq underlying then this else FlexibleType (underlying)
3407
+ case class FlexibleType (original : Type , lo : Type , hi : Type ) extends CachedProxyType with ValueType {
3408
+ def underlying (using Context ): Type = original
3416
3409
3417
- override def computeHash ( bs : Binders ): Int = doHash(bs, underlying)
3410
+ override def superType ( using Context ): Type = hi
3418
3411
3419
- override final def baseClasses (using Context ): List [ClassSymbol ] = underlying.baseClasses
3412
+ def derivedFlexibleType (original : Type )(using Context ): Type =
3413
+ if this .original eq original then this else FlexibleType (original)
3414
+
3415
+ override def computeHash (bs : Binders ): Int = doHash(bs, original)
3416
+
3417
+ override final def baseClasses (using Context ): List [ClassSymbol ] = original.baseClasses
3420
3418
}
3421
3419
3422
3420
object FlexibleType {
3423
- def apply (underlying : Type )(using Context ): FlexibleType = underlying match {
3421
+ def apply (original : Type )(using Context ): FlexibleType = original match {
3424
3422
case ft : FlexibleType => ft
3425
3423
case _ =>
3426
- val hi = underlying .stripNull
3427
- val lo = if hi eq underlying then OrNull (hi) else underlying
3428
- new FlexibleType (underlying , lo, hi)
3424
+ val hi = original .stripNull
3425
+ val lo = if hi eq original then OrNull (hi) else original
3426
+ new FlexibleType (original , lo, hi)
3429
3427
}
3430
3428
3431
3429
def unapply (tp : Type )(using Context ): Option [Type ] = tp match {
3432
- case ft : FlexibleType => Some (ft.underlying )
3430
+ case ft : FlexibleType => Some (ft.original )
3433
3431
case _ => None
3434
3432
}
3435
3433
}
@@ -5699,6 +5697,7 @@ object Types extends TypeUtils {
5699
5697
val args1 = args.zipWithConserve(tparams):
5700
5698
case (arg @ TypeBounds (lo, hi), tparam) =>
5701
5699
boundFollowingVariance(lo, hi, tparam)
5700
+ // TODO: why do we need this?
5702
5701
case (arg : FlexibleType , tparam) =>
5703
5702
boundFollowingVariance(arg.lo, arg.hi, tparam)
5704
5703
case (arg, _) => arg
@@ -5737,7 +5736,7 @@ object Types extends TypeUtils {
5737
5736
case tp : AnnotatedType =>
5738
5737
samClass(tp.underlying)
5739
5738
case tp : FlexibleType =>
5740
- samClass(tp.underlying )
5739
+ samClass(tp.superType )
5741
5740
case _ =>
5742
5741
NoSymbol
5743
5742
0 commit comments