Skip to content

Commit 9125f58

Browse files
oderskyBlaisorblade
authored andcommitted
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 7659c11 commit 9125f58

File tree

5 files changed

+15
-29
lines changed

5 files changed

+15
-29
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,18 @@ class CheckRealizable(implicit ctx: Context) {
7474
def realizability(tp: Type): Realizability = tp.dealias match {
7575
case tp: TermRef =>
7676
val sym = tp.symbol
77-
if (sym.is(Stable)) realizability(tp.prefix)
78-
else {
79-
val r =
80-
if (!sym.isStable) NotStable
81-
else if (!isLateInitialized(sym)) realizability(tp.prefix)
82-
else if (!sym.isEffectivelyFinal) new NotFinal(sym)
83-
else realizability(tp.info).mapError(r => new ProblemInUnderlying(tp.info, r))
84-
if (r == Realizable) sym.setFlag(Stable)
85-
r
86-
}
77+
val r =
78+
if (sym.is(Stable)) realizability(tp.prefix)
79+
else {
80+
val r =
81+
if (!sym.isStable) NotStable
82+
else if (!isLateInitialized(sym)) realizability(tp.prefix)
83+
else if (!sym.isEffectivelyFinal) new NotFinal(sym)
84+
else realizability(tp.info).mapError(r => new ProblemInUnderlying(tp.info, r))
85+
if (r == Realizable) sym.setFlag(Stable)
86+
r
87+
}
88+
if (r == Realizable || tp.info.isStableRealizable) Realizable else r
8789
case _: SingletonType | NoPrefix =>
8890
Realizable
8991
case tp =>

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

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ trait TypeAssigner {
353353
*/
354354
def safeSubstParam(tp: Type, pref: ParamRef, argType: Type, initVariance: Int = 1)(implicit ctx: Context) = {
355355
val tp1 = tp.substParam(pref, argType)
356-
if ((tp1 eq tp) || argType.isRealizable) tp1
356+
if ((tp1 eq tp) || argType.isStableRealizable) tp1
357357
else {
358358
val widenedArgType = argType.widen
359359
if (realizability(widenedArgType) == Realizable)

tests/neg/z1720.scala

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/pos/z1720.scala

Lines changed: 1 addition & 1 deletion
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)