diff options
author | Stefan Zeiger <szeiger@novocode.com> | 2016-02-05 18:22:49 +0100 |
---|---|---|
committer | Stefan Zeiger <szeiger@novocode.com> | 2016-02-08 15:20:05 +0100 |
commit | fbba81991e69faf3e7416b4caabed1e99c528917 (patch) | |
tree | 3e0a59a9f82bab410bb4b2320a49376fff5a1bec /test/files | |
parent | 353c305b13a8b0fbb622e157eabcdd7c69e8ddca (diff) | |
download | scala-fbba81991e69faf3e7416b4caabed1e99c528917.tar.gz scala-fbba81991e69faf3e7416b4caabed1e99c528917.tar.bz2 scala-fbba81991e69faf3e7416b4caabed1e99c528917.zip |
SI-9574 Prevent illegal overrides of members with module types
Commit f32a32b1b33c9d7ccd62467e3e10cb69930023c8 introduced the ability
to override objects with other objects. The exception that allows
these overrides (where the usual subtyping check fails) was applied to
all members whose type is a module class. This is too broad, however,
because it not only applies to members of the form `object foo` but
also `def foo: bar.type` (where `bar` is an `object`).
The fix is to restrict the exception to those cases where both
definitions actually are objects.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/neg/override-object-no.check | 10 | ||||
-rw-r--r-- | test/files/neg/override-object-no.scala | 11 |
2 files changed, 20 insertions, 1 deletions
diff --git a/test/files/neg/override-object-no.check b/test/files/neg/override-object-no.check index 9cfda80fc3..972a719b3b 100644 --- a/test/files/neg/override-object-no.check +++ b/test/files/neg/override-object-no.check @@ -20,4 +20,12 @@ an overriding object must conform to the overridden object's class bound; required: case2.Bar[Traversable[String]] override object A extends Bar[List[String]] // err ^ -four errors found +override-object-no.scala:52: error: overriding method x in trait A of type => SI9574.Foo.type; + method x has incompatible type + trait B extends A { def x: Bar.type } // should not compile (SI-9574) + ^ +override-object-no.scala:53: error: overriding method x in trait A of type => SI9574.Foo.type; + object x has incompatible type + trait C extends A { override object x } + ^ +6 errors found diff --git a/test/files/neg/override-object-no.scala b/test/files/neg/override-object-no.scala index 745cdb2332..517408886d 100644 --- a/test/files/neg/override-object-no.scala +++ b/test/files/neg/override-object-no.scala @@ -43,3 +43,14 @@ package case2 { override object A extends Bar[List[String]] // err } } + +// Both overridden and overriding members must be objects, not vals with a module type +object SI9574 { + object Foo + object Bar + trait A { def x: Foo.type } + trait B extends A { def x: Bar.type } // should not compile (SI-9574) + trait C extends A { override object x } + trait D { object x; def y = x } + trait E extends D { override val x: super.x.type = y } // OK but doesn't need object subtyping exception +} |