Skip to content

Commit 8389bea

Browse files
committed
Align isRealizable with isStable
A TermRef is stable if its underlying type is stable. Realizability should behave the same way. This obviates the change in z1720.scala.
1 parent cf6e895 commit 8389bea

File tree

5 files changed

+15
-29
lines changed

5 files changed

+15
-29
lines changed

compiler/src/dotty/tools/dotc/core/CheckRealizable.scala

+12-10
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,18 @@ class CheckRealizable(implicit ctx: Context) {
7272
def realizability(tp: Type): Realizability = tp.dealias match {
7373
case tp: TermRef =>
7474
val sym = tp.symbol
75-
if (sym.is(Stable)) realizability(tp.prefix)
76-
else {
77-
val r =
78-
if (!sym.isStable) NotStable
79-
else if (!isLateInitialized(sym)) realizability(tp.prefix)
80-
else if (!sym.isEffectivelyFinal) new NotFinal(sym)
81-
else realizability(tp.info).mapError(r => new ProblemInUnderlying(tp.info, r))
82-
if (r == Realizable) sym.setFlag(Stable)
83-
r
84-
}
75+
val r =
76+
if (sym.is(Stable)) realizability(tp.prefix)
77+
else {
78+
val r =
79+
if (!sym.isStable) NotStable
80+
else if (!isLateInitialized(sym)) realizability(tp.prefix)
81+
else if (!sym.isEffectivelyFinal) new NotFinal(sym)
82+
else realizability(tp.info).mapError(r => new ProblemInUnderlying(tp.info, r))
83+
if (r == Realizable) sym.setFlag(Stable)
84+
r
85+
}
86+
if (r == Realizable || tp.info.isStableRealizable) Realizable else r
8587
case _: SingletonType | NoPrefix =>
8688
Realizable
8789
case tp =>

compiler/src/dotty/tools/dotc/core/Types.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ object Types {
159159
/** Does this type denote a realizable stable reference? Much more expensive to check
160160
* than isStable, that's why some of the checks are done later in PostTyper.
161161
*/
162-
final def isRealizable(implicit ctx: Context): Boolean =
162+
final def isStableRealizable(implicit ctx: Context): Boolean =
163163
isStable && realizability(this) == Realizable
164164

165165
/** Is this type a (possibly refined or applied or aliased) type reference

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ trait TypeAssigner {
350350
*/
351351
def safeSubstParam(tp: Type, pref: ParamRef, argType: Type, initVariance: Int = 1)(implicit ctx: Context) = {
352352
val tp1 = tp.substParam(pref, argType)
353-
if ((tp1 eq tp) || argType.isRealizable) tp1
353+
if ((tp1 eq tp) || argType.isStableRealizable) tp1
354354
else {
355355
val widenedArgType = argType.widen
356356
if (realizability(widenedArgType) == Realizable)

tests/neg/z1720.scala

-16
This file was deleted.

tests/pos/z1720.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package test
33
class Thing {
44
def info: Info[this.type] = InfoRepository.getInfo(this)
55
def info2: Info[this.type] = {
6-
val self: this.type = this
6+
def self: this.type = this
77
InfoRepository.getInfo(self)
88
}
99
}

0 commit comments

Comments
 (0)