From 2524fdde3edc7b668fdb4bf68e990141d3ec18d6 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sun, 12 Jan 2014 18:12:29 +0100 Subject: SI-8143 Regressions with override checks, private members These regressed in e609f1f20b, which excluded all private methods from overriding checks. We should only exclude private[this] members on the low end of a pair, as was done before that commit, and, we must also exclude private members on the high side. Why? Warning: reverse engineered intuition follows. We need to report an error when if a private method in a subclass has matches a less-private method in the super class and report an error, lest the user be fooled into thinking it might be invoked virtually. On the other hand, adding a private method to a super class shouldn't invalidate the choice names of public members in its superclasses. I've removed the test case added by that commit and will lodge a reworked version of it that Paul provided as a new issue. That shows a bug with qualified private + inheritance. In addition, the expectation of `neg/accesses.check` is reverted to its 2.10.3 version, which I believe is correct. When it was changed in e609f1f20b it sprouted a variation, `neg/accesses-2`, which has now changed behaviour. The intent of that test will be captured in the aforementioned issue covering qualified private inheritance. --- test/files/neg/accesses.check | 6 +++++- test/files/neg/accesses2.check | 10 +++++++++- test/files/neg/t8143a.check | 5 +++++ test/files/neg/t8143a.scala | 15 +++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 test/files/neg/t8143a.check create mode 100644 test/files/neg/t8143a.scala (limited to 'test/files/neg') diff --git a/test/files/neg/accesses.check b/test/files/neg/accesses.check index 5a5e03233e..db58af12ce 100644 --- a/test/files/neg/accesses.check +++ b/test/files/neg/accesses.check @@ -1,3 +1,7 @@ +accesses.scala:23: error: overriding method f2 in class A of type ()Unit; + method f2 has weaker access privileges; it should not be private + private def f2(): Unit = () + ^ accesses.scala:24: error: overriding method f3 in class A of type ()Unit; method f3 has weaker access privileges; it should be at least protected private[p2] def f3(): Unit = () @@ -10,4 +14,4 @@ accesses.scala:26: error: overriding method f5 in class A of type ()Unit; method f5 has weaker access privileges; it should be at least protected[p1] protected[p2] def f5(): Unit ^ -three errors found +four errors found diff --git a/test/files/neg/accesses2.check b/test/files/neg/accesses2.check index 554a7b4c81..66cf9a116e 100644 --- a/test/files/neg/accesses2.check +++ b/test/files/neg/accesses2.check @@ -1,4 +1,12 @@ +accesses2.scala:6: error: overriding method f2 in class A of type ()Int; + method f2 has weaker access privileges; it should not be private + private def f2(): Int = 1 + ^ accesses2.scala:5: error: class B1 needs to be abstract, since method f2 in class A of type ()Int is not defined class B1 extends A { ^ -one error found +accesses2.scala:9: error: overriding method f2 in class A of type ()Int; + method f2 has weaker access privileges; it should not be private + private def f2(): Int = 1 + ^ +three errors found diff --git a/test/files/neg/t8143a.check b/test/files/neg/t8143a.check new file mode 100644 index 0000000000..4e11000a2a --- /dev/null +++ b/test/files/neg/t8143a.check @@ -0,0 +1,5 @@ +t8143a.scala:2: error: overriding method f in class Foo of type => Int; + method f has weaker access privileges; it should not be private +class Bar extends Foo { private def f = 10 } + ^ +one error found diff --git a/test/files/neg/t8143a.scala b/test/files/neg/t8143a.scala new file mode 100644 index 0000000000..4ec539e671 --- /dev/null +++ b/test/files/neg/t8143a.scala @@ -0,0 +1,15 @@ +class Foo { def f = 5 } +class Bar extends Foo { private def f = 10 } + + +class Foo1 { private def f = 5 } +class Bar1 extends Foo1 { def f = 10 } // okay + +class Foo2 { private def f = 5 } +class Bar2 extends Foo2 { private def f = 10 } // okay + +class Foo3 { private[this] def f = 5 } +class Bar3 extends Foo3 { private def f = 10 } // okay + +class Foo4 { private def f = 5 } +class Bar4 extends Foo4 { private[this] def f = 10 } // okay \ No newline at end of file -- cgit v1.2.3