@@ -307,7 +307,7 @@ object Types extends TypeUtils {
307
307
isRef(defn.ObjectClass ) && (typeSymbol eq defn.FromJavaObjectSymbol )
308
308
309
309
def containsFromJavaObject (using Context ): Boolean = this match
310
- case tp : FlexibleType => tp.original .containsFromJavaObject
310
+ case tp : FlexibleType => tp.underlying .containsFromJavaObject
311
311
case tp : OrType => tp.tp1.containsFromJavaObject || tp.tp2.containsFromJavaObject
312
312
case tp : AndType => tp.tp1.containsFromJavaObject && tp.tp2.containsFromJavaObject
313
313
case _ => isFromJavaObject
@@ -376,7 +376,7 @@ object Types extends TypeUtils {
376
376
case AppliedType (tycon, args) => tycon.unusableForInference || args.exists(_.unusableForInference)
377
377
case RefinedType (parent, _, rinfo) => parent.unusableForInference || rinfo.unusableForInference
378
378
case TypeBounds (lo, hi) => lo.unusableForInference || hi.unusableForInference
379
- case FlexibleType (underlying) => underlying.unusableForInference
379
+ case tp : FlexibleType => tp. underlying.unusableForInference
380
380
case tp : AndOrType => tp.tp1.unusableForInference || tp.tp2.unusableForInference
381
381
case tp : LambdaType => tp.resultType.unusableForInference || tp.paramInfos.exists(_.unusableForInference)
382
382
case WildcardType (optBounds) => optBounds.unusableForInference
@@ -3458,49 +3458,43 @@ object Types extends TypeUtils {
3458
3458
3459
3459
/* A flexible type is a type with a custom subtyping relationship.
3460
3460
* It is used by explicit nulls to represent a type coming from Java which can be
3461
- * consider as nullable or non-nullable depending on the context, in a similar way to Platform
3461
+ * considered as nullable or non-nullable depending on the context, in a similar way to Platform
3462
3462
* Types in Kotlin. A `FlexibleType(T)` generally behaves like a type variable with special bounds
3463
3463
* `T | Null .. T`, so that `T | Null <: FlexibleType(T) <: T`.
3464
3464
* A flexible type will be erased to its original type `T`.
3465
3465
*/
3466
- case class FlexibleType (original : Type , lo : Type , hi : Type ) extends CachedProxyType with ValueType {
3467
- def underlying (using Context ): Type = original
3466
+ case class FlexibleType (lo : Type , hi : Type ) extends CachedProxyType with ValueType {
3468
3467
3469
- override def superType (using Context ): Type = hi
3468
+ override def underlying (using Context ): Type = hi
3470
3469
3471
- def derivedFlexibleType (original : Type )(using Context ): Type =
3472
- if this .original eq original then this else FlexibleType (original )
3470
+ def derivedFlexibleType (hi : Type )(using Context ): Type =
3471
+ if hi eq this .hi then this else FlexibleType (hi )
3473
3472
3474
- override def computeHash (bs : Binders ): Int = doHash(bs, original )
3473
+ override def computeHash (bs : Binders ): Int = doHash(bs, hi )
3475
3474
3476
- override final def baseClasses (using Context ): List [ClassSymbol ] = original .baseClasses
3475
+ override final def baseClasses (using Context ): List [ClassSymbol ] = hi .baseClasses
3477
3476
}
3478
3477
3479
3478
object FlexibleType {
3480
- def apply (original : Type )(using Context ): Type = original match {
3479
+ def apply (tp : Type )(using Context ): Type = tp match {
3481
3480
case ft : FlexibleType => ft
3482
3481
case _ =>
3483
- // val original1 = original .stripNull
3484
- // if original1 .isNullType then
3482
+ // val tp1 = tp .stripNull
3483
+ // if tp1 .isNullType then
3485
3484
// // (Null)? =:= ? >: Null <: (Object & Null)
3486
- // FlexibleType(defn.NullType, original , AndType(defn.ObjectType, defn.NullType))
3485
+ // FlexibleType(tp , AndType(defn.ObjectType, defn.NullType))
3487
3486
// else
3488
3487
// // (T | Null)? =:= ? >: T | Null <: T
3489
3488
// // (T)? =:= ? >: T | Null <: T
3490
- // val hi = original1
3491
- // val lo = if hi eq original then OrNull(hi) else original
3492
- // FlexibleType(original, lo, hi)
3489
+ // val hi = tp1
3490
+ // val lo = if hi eq tp then OrNull(hi) else tp
3491
+ // FlexibleType(lo, hi)
3493
3492
//
3494
3493
// The commented out code does more work to analyze the original type to ensure the
3495
3494
// flexible type is always a subtype of the original type and the Object type.
3496
3495
// It is not necessary according to the use cases, so we choose to use a simpler
3497
3496
// rule.
3498
- FlexibleType (original, OrNull (original), original)
3499
- }
3500
-
3501
- def unapply (tp : Type )(using Context ): Option [Type ] = tp match {
3502
- case ft : FlexibleType => Some (ft.original)
3503
- case _ => None
3497
+ FlexibleType (OrNull (tp), tp)
3504
3498
}
3505
3499
}
3506
3500
@@ -6007,7 +6001,7 @@ object Types extends TypeUtils {
6007
6001
case tp : AnnotatedType =>
6008
6002
samClass(tp.underlying)
6009
6003
case tp : FlexibleType =>
6010
- samClass(tp.superType )
6004
+ samClass(tp.underlying )
6011
6005
case _ =>
6012
6006
NoSymbol
6013
6007
@@ -6138,8 +6132,8 @@ object Types extends TypeUtils {
6138
6132
tp.derivedJavaArrayType(elemtp)
6139
6133
protected def derivedExprType (tp : ExprType , restpe : Type ): Type =
6140
6134
tp.derivedExprType(restpe)
6141
- protected def derivedFlexibleType (tp : FlexibleType , under : Type ): Type =
6142
- tp.derivedFlexibleType(under )
6135
+ protected def derivedFlexibleType (tp : FlexibleType , hi : Type ): Type =
6136
+ tp.derivedFlexibleType(hi )
6143
6137
// note: currying needed because Scala2 does not support param-dependencies
6144
6138
protected def derivedLambdaType (tp : LambdaType )(formals : List [tp.PInfo ], restpe : Type ): Type =
6145
6139
tp.derivedLambdaType(tp.paramNames, formals, restpe)
@@ -6264,7 +6258,7 @@ object Types extends TypeUtils {
6264
6258
derivedOrType(tp, this (tp.tp1), this (tp.tp2))
6265
6259
6266
6260
case tp : FlexibleType =>
6267
- derivedFlexibleType(tp, this (tp.underlying ))
6261
+ derivedFlexibleType(tp, this (tp.hi ))
6268
6262
6269
6263
case tp : MatchType =>
6270
6264
val bound1 = this (tp.bound)
@@ -6553,14 +6547,17 @@ object Types extends TypeUtils {
6553
6547
if (underlying.isExactlyNothing) underlying
6554
6548
else tp.derivedAnnotatedType(underlying, annot)
6555
6549
}
6556
- override protected def derivedFlexibleType (tp : FlexibleType , underlying : Type ): Type =
6557
- underlying match {
6550
+
6551
+ override protected def derivedFlexibleType (tp : FlexibleType , hi : Type ): Type =
6552
+ hi match {
6558
6553
case Range (lo, hi) =>
6559
- range(tp.derivedFlexibleType(lo), tp.derivedFlexibleType(hi))
6554
+ // We know FlexibleType(t).hi = t and FlexibleType(t).lo = OrNull(t)
6555
+ range(OrNull (lo), hi)
6560
6556
case _ =>
6561
- if (underlying .isExactlyNothing) underlying
6562
- else tp.derivedFlexibleType(underlying )
6557
+ if (hi .isExactlyNothing) hi
6558
+ else tp.derivedFlexibleType(hi )
6563
6559
}
6560
+
6564
6561
override protected def derivedCapturingType (tp : Type , parent : Type , refs : CaptureSet ): Type =
6565
6562
parent match // TODO ^^^ handle ranges in capture sets as well
6566
6563
case Range (lo, hi) =>
0 commit comments