Skip to content

Commit 58aabb4

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. Part 1 of 9125f58.
1 parent 8475876 commit 58aabb4

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

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

+13-11
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,20 @@ class CheckRealizable(implicit ctx: Context) {
7070
def realizability(tp: Type): Realizability = tp.dealias match {
7171
case tp: TermRef =>
7272
val sym = tp.symbol
73-
if (sym.is(Stable)) realizability(tp.prefix)
74-
else {
75-
val r =
76-
if (!sym.isStable) NotStable
77-
else if (!isLateInitialized(sym)) Realizable
78-
else if (!sym.isEffectivelyFinal) new NotFinal(sym)
79-
else realizability(tp.info).mapError(r => new ProblemInUnderlying(tp.info, r))
80-
r andAlso {
81-
sym.setFlag(Stable)
82-
realizability(tp.prefix)
73+
val r =
74+
if (sym.is(Stable)) realizability(tp.prefix)
75+
else {
76+
val r =
77+
if (!sym.isStable) NotStable
78+
else if (!isLateInitialized(sym)) Realizable
79+
else if (!sym.isEffectivelyFinal) new NotFinal(sym)
80+
else realizability(tp.info).mapError(r => new ProblemInUnderlying(tp.info, r))
81+
r andAlso {
82+
sym.setFlag(Stable)
83+
realizability(tp.prefix)
84+
}
8385
}
84-
}
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

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Denotations._
1818
import Periods._
1919
import util.Stats._
2020
import util.SimpleIdentitySet
21+
import CheckRealizable._
2122
import reporting.diagnostic.Message
2223
import ast.tpd._
2324
import ast.TreeTypeMap
@@ -157,6 +158,12 @@ object Types {
157158
case _ => false
158159
}
159160

161+
/** Does this type denote a realizable stable reference? Much more expensive to check
162+
* than isStable, that's why some of the checks are done later in PostTyper.
163+
*/
164+
final def isStableRealizable(implicit ctx: Context): Boolean =
165+
isStable && realizability(this) == Realizable
166+
160167
/** Is this type a (possibly refined or applied or aliased) type reference
161168
* to the given type symbol?
162169
* @sym The symbol to compare to. It must be a class symbol or abstract type.

0 commit comments

Comments
 (0)