summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2011-04-08 16:31:26 +0000
committerMartin Odersky <odersky@gmail.com>2011-04-08 16:31:26 +0000
commit26c3f65241f49d96e2b3e853f71aa780ca8861c1 (patch)
tree8cc94c67ca1a884ace6333e00d8cb8c44e9dcdef
parentb13ef720c09f1a7b6e3263faebcb0be7785a5337 (diff)
downloadscala-26c3f65241f49d96e2b3e853f71aa780ca8861c1.tar.gz
scala-26c3f65241f49d96e2b3e853f71aa780ca8861c1.tar.bz2
scala-26c3f65241f49d96e2b3e853f71aa780ca8861c1.zip
Closes #4431. Review by extempore.
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/RefChecks.scala7
-rw-r--r--test/files/neg/t4431.check7
-rw-r--r--test/files/neg/t4431.scala16
3 files changed, 30 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
index 18413de51f..3eb5107870 100644
--- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
@@ -550,6 +550,13 @@ abstract class RefChecks extends InfoTransform {
if (abstractErrors.nonEmpty)
unit.error(clazz.pos, abstractErrorMessage)
+ } else if (clazz.isTrait) {
+ // prevent abstract methods in interfaces that override final members in Object; see #4431
+ for (decl <- clazz.info.decls.iterator) {
+ val overridden = decl.overriddenSymbol(ObjectClass)
+ if (overridden.isFinal)
+ unit.error(decl.pos, "trait cannot redefine final method from class AnyRef")
+ }
}
/** Returns whether there is a symbol declared in class `inclazz`
diff --git a/test/files/neg/t4431.check b/test/files/neg/t4431.check
new file mode 100644
index 0000000000..7896ec1a62
--- /dev/null
+++ b/test/files/neg/t4431.check
@@ -0,0 +1,7 @@
+t4431.scala:5: error: class BB needs to be abstract, since there is a deferred declaration of method f which is not implemented in a subclass
+ class BB extends B { def f (): Unit }
+ ^
+t4431.scala:8: error: trait cannot redefine final method from class AnyRef
+ trait C { def wait (): Unit }
+ ^
+two errors found
diff --git a/test/files/neg/t4431.scala b/test/files/neg/t4431.scala
new file mode 100644
index 0000000000..5fbb239e04
--- /dev/null
+++ b/test/files/neg/t4431.scala
@@ -0,0 +1,16 @@
+object Test {
+ // this works.
+ class B { final def f(): Unit = () }
+ trait A extends B { def f (): Unit }
+ class BB extends B { def f (): Unit }
+
+ // this earns a VerifyError.
+ trait C { def wait (): Unit }
+ class D { }
+
+ def main(args: Array[String]): Unit = {
+ new B with A { }
+ new BB
+// new D with C { }
+ }
+}