scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

serious regression in 2.8.1RC3 #3934

Closed scabug closed 13 years ago

scabug commented 14 years ago

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.

// J.java
package test;

public class J {
  int f1() { return 5; }
  protected int f2() { return 5; }
}

// S.scala
package test
package nest

class S1 {
  def g1(x: J) = x.f1()
  def g2(x: J) = x.f2()
}

class S2 extends J {
  def g1(x: J) = x.f1()
  def g2(x: J) = x.f2()
}
// 2.8.0 compiles as it should
% scalac28 -d . J.java S.scala

// 2.8.1RC3 does not: all four variations excluded!
% rcscalac J.java S.scala 
S.scala:5: error: method f1 cannot be accessed in test.J
  def g1(x: J) = x.f1()
                   ^
S.scala:6: error: method f2 cannot be accessed in test.J
  def g2(x: J) = x.f2()
                   ^
S.scala:10: error: method f1 cannot be accessed in test.J
  def g1(x: J) = x.f1()
                   ^
S.scala:11: error: method f2 cannot be accessed in test.J
  def g2(x: J) = x.f2()
                   ^
four errors found

// same result compiling against bytecode
% rcscalac -cp . -d . S.scala 
S.scala:5: error: method f1 cannot be accessed in test.J
  def g1(x: J) = x.f1()
                   ^
S.scala:6: error: method f2 cannot be accessed in test.J
  def g2(x: J) = x.f2()
                   ^
S.scala:10: error: method f1 cannot be accessed in test.J
  def g1(x: J) = x.f1()
                   ^
S.scala:11: error: method f2 cannot be accessed in test.J
  def g2(x: J) = x.f2()
                   ^
four errors found
% rcscalac -version
Scala compiler version 2.8.1.RC3 -- Copyright 2002-2010, LAMP/EPFL

Regression was in RC1 and RC2 as well.

scabug commented 14 years ago

Imported From: https://issues.scala-lang.org/browse/SI-3934?orig=1 Reporter: @paulp

scabug commented 14 years ago

@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
scabug commented 14 years ago

@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.

scabug commented 14 years ago

@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.

scabug commented 14 years ago

@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.

scabug commented 13 years ago

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.