From ec4a3a0f4d0b8cccf636d1608896e7cafba9dec0 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 2 Feb 2016 10:21:12 +0100 Subject: Big realizability refactoring Move logic from TypeOps to new file CheckRealizable.scala. Also check realizable fields under strict mode. Check at phase PostTyper rather than Typer to avoid cycles. New tests for imports and deep paths. --- tests/neg/cycles.scala | 4 +- tests/neg/i1050.scala | 119 ++++++++++++++++++++++++++++++++++++------------- tests/neg/i1050a.scala | 9 ++-- tests/neg/i1050c.scala | 31 +++++++++++++ tests/neg/ski.scala | 4 +- 5 files changed, 129 insertions(+), 38 deletions(-) create mode 100644 tests/neg/i1050c.scala (limited to 'tests') diff --git a/tests/neg/cycles.scala b/tests/neg/cycles.scala index 550bc98ea..ced6f56b5 100644 --- a/tests/neg/cycles.scala +++ b/tests/neg/cycles.scala @@ -13,7 +13,7 @@ class B { } class C { - final val x: D#T = ??? // error: conflicting bounds + final val x: D#T = ??? class D { type T <: x.type // error: cycle val z: x.type = ??? @@ -25,7 +25,7 @@ class E { type T <: x.type // error: not stable val z: x.type = ??? // error: not stable } - lazy val x: F#T = ??? // error: conflicting bounds + lazy val x: F#T = ??? } class T1 { diff --git a/tests/neg/i1050.scala b/tests/neg/i1050.scala index f2c237af2..fb4160606 100644 --- a/tests/neg/i1050.scala +++ b/tests/neg/i1050.scala @@ -1,3 +1,4 @@ +// i1050 checks failing at posttyper trait A { type L <: Nothing } trait B { type L >: Any} object Test { @@ -79,36 +80,6 @@ object Tiark3 { val v = new V {} v.brand("boom!"): Nothing } -object Tiark4 { - trait U { - type Y - trait X { type L = Y } - def compute: X - final lazy val p: X = compute - def brand(x: Y): p.L = x - } - trait V extends U { - type Y >: Any <: Nothing - def compute: X = ??? - } - val v = new V {} // error: cannot be instantiated - v.brand("boom!") -} -object Import { - trait A { type L <: Nothing } - trait B { type L >: Any} - trait U { - lazy val p: B - locally { val x: p.L = ??? } // error: nonfinal lazy - locally { - import p._ - val x: L = ??? // error: nonfinal lazy - } - } -} -object V { // error: cannot be instantiated - type Y >: Any <: Nothing // error: only classes can have declared but undefined members -} object Tiark5 { trait A { type L <: Nothing } trait B { type L >: Any } @@ -136,3 +107,91 @@ object Tiark6 { val v = new U {} v.brand("boom!"): Nothing } + +object Indirect { + trait B { type L >: Any } + trait A { type L <: Nothing } + trait U { + trait X { + val q: A & B = ??? + type M = q.L + } + final lazy val p: X = ??? + def brand(x: Any): p.M = x // error: conflicting bounds + } + def main(args: Array[String]): Unit = { + val v = new U {} + v.brand("boom!"): Nothing + } +} +object Indirect2 { + trait B { type L >: Any } + trait A { type L <: Nothing } + trait U { + trait Y { + val r: A & B = ??? + } + trait X { + val q: Y = ??? + type M = q.r.L + } + final lazy val p: X = ??? + def brand(x: Any): p.M = x // error: conflicting bounds + } + def main(args: Array[String]): Unit = { + val v = new U {} + v.brand("boom!"): Nothing + } +} +object Rec1 { + trait B { type L >: Any } + trait A { type L <: Nothing } + trait U { + trait Y { + type L = Int + val r: Y + } + trait X { + val q: Y = ??? + type M = q.r.L // if we are not careful we get a stackoverflow here + } + } +} +object Rec2 { + trait B { type L >: Any } + trait A { type L <: Nothing } + trait U { + trait Y { + val r: A & B & Y + } + trait X { + val q: Y = ??? + type M = q.r.L + } + final lazy val p: X = ??? + def brand(x: Any): p.M = x // error: conflicting bounds + } + def main(args: Array[String]): Unit = { + val v = new U {} + v.brand("boom!"): Nothing + } +} +object Indirect3 { + trait B { type L >: Any } + trait A { type L <: Nothing } + trait U { + trait Y { + val r: Y & A & B = ??? + } + trait X { + val q: Y = ??? + type M = q.r.L + } + final lazy val p: X = ??? + def brand(x: Any): p.M = x // error: conflicting bounds + } + def main(args: Array[String]): Unit = { + val v = new U {} + v.brand("boom!"): Nothing + } +} diff --git a/tests/neg/i1050a.scala b/tests/neg/i1050a.scala index 47e2f0c59..4fea5e3b1 100644 --- a/tests/neg/i1050a.scala +++ b/tests/neg/i1050a.scala @@ -1,12 +1,13 @@ +// i1050 checks failing at refchecks object Tiark1 { trait A { type L <: Nothing } trait B { type L >: Any} trait U { val p: B - def brand(x: Any): p.L = x // error: not final + def brand(x: Any): p.L = x } trait V extends U { - lazy val p: A & B = ??? + lazy val p: A & B = ??? // error: may not override } val v = new V {} v.brand("boom!") @@ -17,11 +18,11 @@ object Tiark2 { trait U { type X <: B val p: X - def brand(x: Any): p.L = x // error: not final + def brand(x: Any): p.L = x } trait V extends U { type X = B & A - lazy val p: X = ??? + lazy val p: X = ??? // error: may not override } val v = new V {} v.brand("boom!"): Nothing diff --git a/tests/neg/i1050c.scala b/tests/neg/i1050c.scala new file mode 100644 index 000000000..ece1f9986 --- /dev/null +++ b/tests/neg/i1050c.scala @@ -0,0 +1,31 @@ +// i1050 checks failing at typer +object Import { + trait A { type L <: Nothing } + trait B { type L >: Any} + trait U { + lazy val p: B + locally { val x: p.L = ??? } // error: nonfinal lazy + locally { + import p._ + val x: L = ??? // error: nonfinal lazy + } + } +} +object Tiark4 { + trait U { + type Y + trait X { type L = Y } + def compute: X + final lazy val p: X = compute + def brand(x: Y): p.L = x + } + trait V extends U { + type Y >: Any <: Nothing + def compute: X = ??? + } + val v = new V {} // error: cannot be instantiated + v.brand("boom!") +} +object V { // error: cannot be instantiated + type Y >: Any <: Nothing // error: only classes can have declared but undefined members +} diff --git a/tests/neg/ski.scala b/tests/neg/ski.scala index 8fb35c7f2..b192dc9e2 100644 --- a/tests/neg/ski.scala +++ b/tests/neg/ski.scala @@ -64,9 +64,9 @@ case class Equals[A >: B <:B , B]() object Test { type T1 = Equals[Int, Int] // compiles fine - type T2 = Equals[String, Int] // was error, now masked + type T2 = Equals[String, Int] // error type T3 = Equals[I#ap[c]#eval, c] - type T3a = Equals[I#ap[c]#eval, d] // was error, now masked + type T3a = Equals[I#ap[c]#eval, d] // error // Ic -> c type T4 = Equals[I#ap[c]#eval, c] -- cgit v1.2.3