Skip to content

Commit b5331a3

Browse files
authored
Merge pull request #5726 from dotty-staging/realizability-stray-tests
Realizability: extra tests and code fix from #5558
2 parents da1e196 + 0ee31f4 commit b5331a3

File tree

4 files changed

+82
-1
lines changed

4 files changed

+82
-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/neg/i4031-anysel.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test {
2+
val v: Any = 1: Any#L // error
3+
}

tests/pos-deep-subtype/i4036.scala

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
trait A { def x: this.type = this; type T }
2+
trait B { def y: this.type = this; def x: y.type = y; type T }
3+
object A {
4+
val v = new A { type T = Int }
5+
v: v.
6+
x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.
7+
x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.
8+
x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
x.type
43+
44+
val z = new B { type T = this.type }
45+
z: z.T#
46+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
47+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
48+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
49+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
50+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
51+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
52+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
53+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
54+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
55+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
56+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
57+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
58+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
59+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
60+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
61+
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T
62+
}

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)