Skip to content

Commit af4ccf9

Browse files
committed
Singletons of mutable vars with singleton types are realizable
Such a "variable" can only have one value, so this is okay. This goes back to 9125f58.
1 parent 33a68d3 commit af4ccf9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class CheckRealizable(implicit ctx: Context) {
6868
def realizability(tp: Type): Realizability = tp.dealias match {
6969
case tp: TermRef =>
7070
val sym = tp.symbol
71+
lazy val tpInfoRealizable = realizability(tp.info)
7172
if (sym.is(Stable)) realizability(tp.prefix)
7273
else {
7374
val r =
@@ -80,10 +81,12 @@ class CheckRealizable(implicit ctx: Context) {
8081
else
8182
// otherwise we need to look at the info to determine realizability
8283
// roughly: it's realizable if the info does not have bad bounds
83-
realizability(tp.info).mapError(r => new ProblemInUnderlying(tp, r))
84+
tpInfoRealizable.mapError(r => new ProblemInUnderlying(tp, r))
8485
r andAlso {
8586
if (sym.isStable) sym.setFlag(Stable) // it's known to be stable and realizable
8687
realizability(tp.prefix)
88+
} mapError { r =>
89+
if (tp.info.isStable && tpInfoRealizable == Realizable) Realizable else r
8790
}
8891
}
8992
case _: SingletonType | NoPrefix =>

tests/pos/realizable-mut.scala

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object Foo {
2+
val x = new Object
3+
4+
class A(var y: x.type)
5+
6+
val a = new A(x)
7+
8+
val y: a.y.type = x
9+
// 1 |val y: a.y.type = x
10+
// | ^
11+
// | Object(x)(a.y) is not a legal path
12+
// | since it refers to nonfinal variable y
13+
}

0 commit comments

Comments
 (0)