Closed scabug closed 13 years ago
Imported From: https://issues.scala-lang.org/browse/SI-3934?orig=1 Reporter: @paulp
@paulp said: Oh, and it's in trunk too, albeit with martin's recent error message bonuses.
scalac29 J.java S.scala
S.scala:7: error: method f1 in class J cannot be accessed in test.J
def g1(x: J) = x.f1()
^
S.scala:8: error: method f2 in class J cannot be accessed in test.J
Access to protected method f2 not permitted because
enclosing class class S1 in package nest is not a subclass of
class J in package test where target is defined
def g2(x: J) = x.f2()
^
S.scala:12: error: method f1 in class J cannot be accessed in test.J
def g1(x: J) = x.f1()
^
S.scala:13: error: method f2 in class J cannot be accessed in test.J
Access to protected method f2 not permitted because
prefix type test.J does not conform to
def g2(x: J) = x.f2()
^
four errors found
@paulp said: I see that this is a result of #3663 and the description "disregard package nesting for access check of java syms" makes it sound like it's intentional. But it is not at all consonant with my impression of how java access is supposed to be mapped into scala. If the spec carves out an exception for java here I can't find it, but what I can find is martin's source comment. I expanded it recently so I'll rewind to the pure martin one so there is no ambiguity.
Here's a tanslation of Java's accessibility modifiers:
* Java private: PRIVATE flag set, privateWithin == NoSymbol
* Java package: no flag set, privateWithin == enclosing package
* Java protected: PROTECTED flag set, privateWithin == enclosing package
* Java public: no flag set, privateWithin == NoSymbol
Even if the limitation on package-scoped access from a nested package was intentional (which I assume it was not) it cannot be correct that S2, which subclasses J, cannot access a protected member.
@odersky said: This is actually as it should be. All four statements need to be rejected. So it's a bugfix, even though it will invalidate some code. I'll still work on it to improve the error output from triunk though.
@odersky said: (In r23309) Closes #3934 by fixing a typo (missing + in string concat). Better effect analysis would have caught that one at compile-time. Review by extempore.
Joshua Hartman (jhartman) said: Protocol buffers 2.4.0a unfortunately generates protected inner interfaces. As referenced in #4402, these classes won't compile using scalac, making this library rather difficult to use.
Sorry I'm only discovering this now, although it's improbable that I found it at all as I wasn't really looking for regressions.
Regression was in RC1 and RC2 as well.