@@ -160,11 +160,12 @@ object Types {
160
160
* Like in isStableMember, "stability" means idempotence.
161
161
* Rationale: If an expression has a stable type, the expression must be idempotent, so stable types
162
162
* must be singleton types of stable expressions. */
163
- final def isStable (using Context ): Boolean = stripTypeVar match {
163
+ final def isStable (using Context ): Boolean = this match {
164
164
case tp : TermRef => tp.symbol.isStableMember && tp.prefix.isStable || tp.info.isStable
165
165
case _ : SingletonType | NoPrefix => true
166
166
case tp : RefinedOrRecType => tp.parent.isStable
167
167
case tp : ExprType => tp.resultType.isStable
168
+ case tp : AppliedType => tp.appliedTypeIsStable
168
169
case tp : AnnotatedType =>
169
170
// NOTE UncheckedStableAnnot was originally meant to be put on fields,
170
171
// not on types. Allowing it on types is a Scala 3 extension. See:
@@ -4160,11 +4161,23 @@ object Types {
4160
4161
// Boolean caches: 0 = uninitialized, -1 = false, 1 = true
4161
4162
private var myStableHash : Byte = 0
4162
4163
private var myGround : Byte = 0
4164
+ private var myIsStable : Byte = 0
4165
+
4163
4166
4164
4167
def isGround (acc : TypeAccumulator [Boolean ])(using Context ): Boolean =
4165
4168
if myGround == 0 then myGround = if acc.foldOver(true , this ) then 1 else - 1
4166
4169
myGround > 0
4167
4170
4171
+ inline def appliedTypeIsStable (using Context ): Boolean =
4172
+ if myIsStable == 0 then
4173
+ val isStable : Byte = tycon match
4174
+ case tycon : TypeRef if defn.isCompiletimeAppliedType(tycon.symbol) && args.forall(_.isStable) => 1
4175
+ case _ => - 1
4176
+ if ! isProvisional then myIsStable = isStable
4177
+ isStable > 0
4178
+ else
4179
+ myIsStable > 0
4180
+
4168
4181
override def underlying (using Context ): Type = tycon
4169
4182
4170
4183
override def superType (using Context ): Type =
@@ -4242,7 +4255,7 @@ object Types {
4242
4255
// final val one = 1
4243
4256
// type Two = one.type + one.type
4244
4257
// ```
4245
- case tp : TermRef => tp.underlying
4258
+ case tp : TypeProxy if tp.underlying.isStable => tp.underlying.fixForEvaluation
4246
4259
case tp => tp
4247
4260
}
4248
4261
0 commit comments