summaryrefslogtreecommitdiff
path: root/test/files/neg/override-object-no.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-09-08 18:37:18 +0000
committerPaul Phillips <paulp@improving.org>2011-09-08 18:37:18 +0000
commitf32a32b1b33c9d7ccd62467e3e10cb69930023c8 (patch)
tree47ca34246fbdd255f2191ced68bd708e609d22d2 /test/files/neg/override-object-no.scala
parent52c1d019d63d2fffadc8f3f159d654187ac61ece (diff)
downloadscala-f32a32b1b33c9d7ccd62467e3e10cb69930023c8.tar.gz
scala-f32a32b1b33c9d7ccd62467e3e10cb69930023c8.tar.bz2
scala-f32a32b1b33c9d7ccd62467e3e10cb69930023c8.zip
Allow for the overriding of objects.
Various and sundry manipulations to allow for objects to be overridden when the mood is right. It is not enabled by default. The major contributor of change turned out to be the decoupling of the FINAL flag (and the "isFinal" test which examines only that flag) and the many semantics which were attributed to this interpretation of finality in different circumstances. Since objects no longer have the FINAL flag automatically applied (only top-level objects and those marked final in source code do) we need apply a more nuanced test. Fortunately there is such a nuanced test: isEffectivelyFinal, which is always true if the FINAL flag is set but also in various other circumstances. In almost every case, you should be testing "isEffectivelyFinal", not "isFinal". To enable overridable objects, use: -Yoverride-objects -Xexperimental // includes the above and others Remain to be done: working out transition logistics. Most likely this would involve bumping the scala signature version, and all objects in versions before that would be assumed final. Review by moors.
Diffstat (limited to 'test/files/neg/override-object-no.scala')
-rw-r--r--test/files/neg/override-object-no.scala45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/files/neg/override-object-no.scala b/test/files/neg/override-object-no.scala
new file mode 100644
index 0000000000..745cdb2332
--- /dev/null
+++ b/test/files/neg/override-object-no.scala
@@ -0,0 +1,45 @@
+// See also pos/override-object-yes.scala
+
+package case1 {
+ // Missing interface in overriding object
+ class Bippy { def f = 1 }
+ trait Bippo
+
+ trait Foo {
+ object Bar extends Bippy with Bippo { override def f = 2 }
+ def f(x: Bippo)
+ def g = f(Bar)
+ }
+ trait Foo2 extends Foo {
+ override object Bar extends Bippy { // err
+ override def f = 3
+ }
+ }
+
+ // type mismatch in member
+ trait Quux1 { object Bar { def g = 55 } }
+ trait Quux2 extends Quux1 { override object Bar { def g = "abc" } } // err
+
+ // still can't override final objects!
+ trait Quux3 { final object Bar { } }
+ trait Quux4 extends Quux3 { override object Bar } // err
+}
+
+// type parameter as-seen-from business
+package case2 {
+ // invariance (see pos for the covariant case)
+ class Bar[T]
+
+ class Foo[T] {
+ object A extends Bar[T]
+ }
+
+ class Baz[S] extends Foo[S] {
+ override object A extends Bar[S]
+ }
+
+ class P1 extends Foo[Traversable[String]]
+ class P2 extends P1 {
+ override object A extends Bar[List[String]] // err
+ }
+}