@@ -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
@@ -755,8 +754,6 @@ object Types {
755
754
case d : ClassDenotation => d.findMember(name, pre, required, excluded)
756
755
case d => go(d.info)
757
756
}
758
- case tp : FlexibleType =>
759
- go(tp.underlying)
760
757
case tp : AppliedType =>
761
758
tp.tycon match {
762
759
case tc : TypeRef =>
@@ -976,8 +973,6 @@ object Types {
976
973
if (keepOnly(pre, tp.refinedName)) ns + tp.refinedName else ns
977
974
case tp : TypeProxy =>
978
975
tp.superType.memberNames(keepOnly, pre)
979
- case tp : FlexibleType =>
980
- tp.underlying.memberNames(keepOnly, pre)
981
976
case tp : AndType =>
982
977
tp.tp1.memberNames(keepOnly, pre) | tp.tp2.memberNames(keepOnly, pre)
983
978
case tp : OrType =>
@@ -1435,7 +1430,6 @@ object Types {
1435
1430
case tp : ExprType => tp.resType.atoms
1436
1431
case tp : OrType => tp.atoms // `atoms` overridden in OrType
1437
1432
case tp : AndType => tp.tp1.atoms & tp.tp2.atoms
1438
- case tp : FlexibleType => tp.underlying.atoms
1439
1433
case tp : TypeRef if tp.symbol.is(ModuleClass ) =>
1440
1434
// The atom of a module class is the module itself,
1441
1435
// this corresponds to the special case in TypeComparer
@@ -3414,26 +3408,30 @@ object Types {
3414
3408
* in Kotlin. A FlexibleType(T) generally behaves like an abstract type with bad bounds
3415
3409
* T|Null .. T, so that T|Null <: FlexibleType(T) <: T.
3416
3410
*/
3417
- case class FlexibleType (underlying : Type , lo : Type , hi : Type ) extends CachedGroundType with ValueType {
3418
- def derivedFlexibleType (underlying : Type )(using Context ): Type =
3419
- if this .underlying eq underlying then this else FlexibleType (underlying)
3411
+ case class FlexibleType (original : Type , lo : Type , hi : Type ) extends CachedProxyType with ValueType {
3412
+ def underlying (using Context ): Type = original
3420
3413
3421
- override def computeHash ( bs : Binders ): Int = doHash(bs, underlying)
3414
+ override def superType ( using Context ): Type = hi
3422
3415
3423
- override final def baseClasses (using Context ): List [ClassSymbol ] = underlying.baseClasses
3416
+ def derivedFlexibleType (original : Type )(using Context ): Type =
3417
+ if this .original eq original then this else FlexibleType (original)
3418
+
3419
+ override def computeHash (bs : Binders ): Int = doHash(bs, original)
3420
+
3421
+ override final def baseClasses (using Context ): List [ClassSymbol ] = original.baseClasses
3424
3422
}
3425
3423
3426
3424
object FlexibleType {
3427
- def apply (underlying : Type )(using Context ): FlexibleType = underlying match {
3425
+ def apply (original : Type )(using Context ): FlexibleType = original match {
3428
3426
case ft : FlexibleType => ft
3429
3427
case _ =>
3430
- val hi = underlying .stripNull
3431
- val lo = if hi eq underlying then OrNull (hi) else underlying
3432
- new FlexibleType (underlying , lo, hi)
3428
+ val hi = original .stripNull
3429
+ val lo = if hi eq original then OrNull (hi) else original
3430
+ new FlexibleType (original , lo, hi)
3433
3431
}
3434
3432
3435
3433
def unapply (tp : Type )(using Context ): Option [Type ] = tp match {
3436
- case ft : FlexibleType => Some (ft.underlying )
3434
+ case ft : FlexibleType => Some (ft.original )
3437
3435
case _ => None
3438
3436
}
3439
3437
}
@@ -5680,6 +5678,7 @@ object Types {
5680
5678
val args1 = args.zipWithConserve(tparams):
5681
5679
case (arg @ TypeBounds (lo, hi), tparam) =>
5682
5680
boundFollowingVariance(lo, hi, tparam)
5681
+ // TODO: why do we need this?
5683
5682
case (arg : FlexibleType , tparam) =>
5684
5683
boundFollowingVariance(arg.lo, arg.hi, tparam)
5685
5684
case (arg, _) => arg
@@ -5718,7 +5717,7 @@ object Types {
5718
5717
case tp : AnnotatedType =>
5719
5718
samClass(tp.underlying)
5720
5719
case tp : FlexibleType =>
5721
- samClass(tp.underlying )
5720
+ samClass(tp.superType )
5722
5721
case _ =>
5723
5722
NoSymbol
5724
5723
0 commit comments