diff options
author | Martin Odersky <odersky@gmail.com> | 2015-02-12 11:28:35 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2015-03-18 11:09:43 +0100 |
commit | 61cb51acaedbe603add8c4af9e390a27f8b33f09 (patch) | |
tree | 2e6f7d2410b96b208b3f6be5c5465a320751d7f0 /tests/neg | |
parent | 3f5d15defa7481da1b9d1f20e91569a340c71e8e (diff) | |
download | dotty-61cb51acaedbe603add8c4af9e390a27f8b33f09.tar.gz dotty-61cb51acaedbe603add8c4af9e390a27f8b33f09.tar.bz2 dotty-61cb51acaedbe603add8c4af9e390a27f8b33f09.zip |
Disallow refinements of types or methods that do not appear in parent.
We planned this for a long time but never implemented it. Instead, we sometimes
issued an erro in Splitter, namely if reflection would have been needed to access the
member. It turns out that some tests (e.g. neg/t625) fail -Ycheck (we knew that before
and disabled) but also fail Pickling because they generate orhpan PolyParams. So rather
than patching this up it seems now is a good time to enforce the restriction for real.
Diffstat (limited to 'tests/neg')
-rw-r--r-- | tests/neg/structural.scala | 70 | ||||
-rw-r--r-- | tests/neg/t0586.scala | 9 | ||||
-rw-r--r-- | tests/neg/t0625.scala | 8 | ||||
-rw-r--r-- | tests/neg/t1131.scala | 4 | ||||
-rw-r--r-- | tests/neg/typers.scala | 4 |
5 files changed, 70 insertions, 25 deletions
diff --git a/tests/neg/structural.scala b/tests/neg/structural.scala new file mode 100644 index 000000000..1d2506290 --- /dev/null +++ b/tests/neg/structural.scala @@ -0,0 +1,70 @@ +package p1 { + +object test123 { + type A = { def a: Int } + def f(a: A): A = a +} + +object structural2 { + type A = { def a: Int } + + type B = { + def b: Int + } + + type AB = A & B + + def f(ab: AB): AB = ab + + f(new { + def a = 43 + def b = 42 + }) +} +} + +package p2 { +object RClose { + type ReflectCloseable = { def close(): Unit } + def withReflectCloseable[T <: ReflectCloseable, R](s: T)(action: T => R): R = + try { + action(s) + } finally { + s.close() + } +} +} + +package p3 { +object Test { + def idMap[C[_],T](m: { def map[U](f: T => U): C[U] }): C[T] = m.map(t => t) + + def main(args: Array[String]): Unit = { + idMap(Some(5)) + idMap(Responder.constant(5)) + } +} +} +package p4 { + +trait A { self: Any { def p: Any } => + def f(b: => Unit): Unit = {} + f { p } // error: cannot access member 'p' from structural type +} +} + +package p5 { +// t2810 +object Test { + val closeable1: { def close(): Unit } = new scala.io.Source { val iter: Iterator[Char] = "".iterator } + val closeable2: { def close(): Unit } = new java.io.Closeable { def close() = {} } +} +} + +package p6 { + + class Refinements { + val y: C { val x: T; type T } // was adeprecated warning: illegal forward reference in refinement; now illegal + } + +} diff --git a/tests/neg/t0586.scala b/tests/neg/t0586.scala deleted file mode 100644 index 540e225a1..000000000 --- a/tests/neg/t0586.scala +++ /dev/null @@ -1,9 +0,0 @@ -object RClose { - type ReflectCloseable = { def close(): Unit } - def withReflectCloseable[T <: ReflectCloseable, R](s: T)(action: T => R): R = - try { - action(s) - } finally { - s.close() - } -} diff --git a/tests/neg/t0625.scala b/tests/neg/t0625.scala deleted file mode 100644 index 561454259..000000000 --- a/tests/neg/t0625.scala +++ /dev/null @@ -1,8 +0,0 @@ -object Test { - def idMap[C[_],T](m: { def map[U](f: T => U): C[U] }): C[T] = m.map(t => t) - - def main(args: Array[String]): Unit = { - idMap(Some(5)) - idMap(Responder.constant(5)) - } -} diff --git a/tests/neg/t1131.scala b/tests/neg/t1131.scala deleted file mode 100644 index f4a7b377d..000000000 --- a/tests/neg/t1131.scala +++ /dev/null @@ -1,4 +0,0 @@ -trait A { self: Any { def p: Any } => - def f(b: => Unit): Unit = {} - f { p } // error: cannot access member 'p' from structural type -} diff --git a/tests/neg/typers.scala b/tests/neg/typers.scala index 226fd2310..b5bd1fa2c 100644 --- a/tests/neg/typers.scala +++ b/tests/neg/typers.scala @@ -60,8 +60,4 @@ object typers { 123 } } - - class Refinements { - val y: C { val x: T; type T } // deprecated warning: illegal forward reference in refinement - } } |