Skip to content

Realizability: extra tests and code fix from #5558 #5726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/core/CheckRealizable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class CheckRealizable(implicit ctx: Context) {
def realizability(tp: Type): Realizability = tp.dealias match {
case tp: TermRef =>
val sym = tp.symbol
lazy val tpInfoRealizable = realizability(tp.info)
if (sym.is(Stable)) realizability(tp.prefix)
else {
val r =
Expand All @@ -80,10 +81,12 @@ class CheckRealizable(implicit ctx: Context) {
else
// otherwise we need to look at the info to determine realizability
// roughly: it's realizable if the info does not have bad bounds
realizability(tp.info).mapError(r => new ProblemInUnderlying(tp, r))
tpInfoRealizable.mapError(r => new ProblemInUnderlying(tp, r))
r andAlso {
if (sym.isStable) sym.setFlag(Stable) // it's known to be stable and realizable
realizability(tp.prefix)
} mapError { r =>
if (tp.info.isStable && tpInfoRealizable == Realizable) Realizable else r
}
}
case _: SingletonType | NoPrefix =>
Expand Down
3 changes: 3 additions & 0 deletions tests/neg/i4031-anysel.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test {
val v: Any = 1: Any#L // error
}
62 changes: 62 additions & 0 deletions tests/pos-deep-subtype/i4036.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
trait A { def x: this.type = this; type T }
trait B { def y: this.type = this; def x: y.type = y; type T }
object A {
val v = new A { type T = Int }
v: v.
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.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T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#
T#T#T#T#T#T#T#T#T#T#T#T#T#T#T#T
}
13 changes: 13 additions & 0 deletions tests/pos/realizable-mut.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
object Foo {
val x = new Object

class A(var y: x.type)

val a = new A(x)

val y: a.y.type = x
// 1 |val y: a.y.type = x
// | ^
// | Object(x)(a.y) is not a legal path
// | since it refers to nonfinal variable y
}