Skip to content

serious regression in 2.8.1RC3 #3934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scabug opened this issue Oct 18, 2010 · 6 comments
Closed

serious regression in 2.8.1RC3 #3934

scabug opened this issue Oct 18, 2010 · 6 comments
Assignees

Comments

@scabug
Copy link

scabug commented Oct 18, 2010

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
Copy link
Author

scabug commented Oct 18, 2010

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

@scabug
Copy link
Author

scabug commented Oct 18, 2010

@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
Copy link
Author

scabug commented Oct 18, 2010

@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
Copy link
Author

scabug commented Oct 19, 2010

@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
Copy link
Author

scabug commented Oct 19, 2010

@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
Copy link
Author

scabug commented Apr 4, 2011

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants