Scala Programming Language
  1. Scala Programming Language
  2. SI-8143

private method shadows directly inherited public method

    Details

      Description

      This does not compile in 2.10, but does in master.

      class Foo { def f = 5 }
      class Bar extends Foo { private def f = 10 }
      

      I think it regressed in e609f1f20b . The test case run/private-override.scala looks wrong - class Other is supposed to be in some package other than p2 to test what it is intending to test. I believe that bug is legit, just the test case is wrong, but also that it is the change which accompanied it which caused the bug being reported here.

        Issue Links

          Activity

          Hide
          Jason Zaugg added a comment - - edited

          For reference, the Java behaviour is like ours in 2.10:

          tail sandbox/{Test,Sub}.java
          ==> sandbox/Test.java <==
          class Test {
          	public int foo() { return 0; }
          }
          
          ==> sandbox/Sub.java <==
          class Sub extends Test {
          	private int foo() { return 0; }
          }
            /code/scala javac sandbox/{Test,Sub}.java
          sandbox/Sub.java:2: foo() in Sub cannot override foo() in Test; attempting to assign weaker access privileges; was public
          	private int foo() { return 0; }
          	            ^
          1 error
          
          Show
          Jason Zaugg added a comment - - edited For reference, the Java behaviour is like ours in 2.10: tail sandbox/{Test,Sub}.java ==> sandbox/Test.java <== class Test { public int foo() { return 0; } } ==> sandbox/Sub.java <== class Sub extends Test { private int foo() { return 0; } } /code/scala javac sandbox/{Test,Sub}.java sandbox/Sub.java:2: foo() in Sub cannot override foo() in Test; attempting to assign weaker access privileges; was public private int foo() { return 0; } ^ 1 error
          Hide
          Paul Phillips added a comment -

          Note that slight variations are allowed even in 2.10 and prior.

          class A { def f = 5 }
          class B extends A { private[B] def f = 10 }
          

          Not sure how that can be acceptable if straight private isn't.

          Show
          Paul Phillips added a comment - Note that slight variations are allowed even in 2.10 and prior. class A { def f = 5 } class B extends A { private[B] def f = 10 } Not sure how that can be acceptable if straight private isn't.
          Hide
          Jason Zaugg added a comment -

          Good catch.

          Seems like every call to `Symbol#isPrivate` represents a potential bug:

          scala> object O { trait T { private[O] def foo = 0 } }
          defined module O
          
          scala> val foo = typeOf[O.T].member(newTermName("foo"))
          foo: $r.intp.global.Symbol = method foo
          
          scala> foo.isPrivate
          res0: Boolean = false
          
          scala> foo.privateWithin
          res1: $r.intp.global.Symbol = object O
          
          // RefChecks
          if (member.isPrivate) // (1.1)
                      overrideError("has weaker access privileges; it should not be private")
                    member.privateWithin
          
          Show
          Jason Zaugg added a comment - Good catch. Seems like every call to `Symbol#isPrivate` represents a potential bug: scala> object O { trait T { private[O] def foo = 0 } } defined module O scala> val foo = typeOf[O.T].member(newTermName("foo")) foo: $r.intp.global.Symbol = method foo scala> foo.isPrivate res0: Boolean = false scala> foo.privateWithin res1: $r.intp.global.Symbol = object O // RefChecks if (member.isPrivate) // (1.1) overrideError("has weaker access privileges; it should not be private") member.privateWithin
          Hide
          Jason Zaugg added a comment -
          Show
          Jason Zaugg added a comment - Fixing the regression: https://github.com/scala/scala/pull/3357
          Hide
          Jason Zaugg added a comment -

          Followup to track the issues with qualified private.

          Show
          Jason Zaugg added a comment - Followup to track the issues with qualified private.

            People

            • Assignee:
              Jason Zaugg
              Reporter:
              Paul Phillips
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development