Skip to content

parameterized java class with protected constructor incorrectly fails, then issues misleading message #6617

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

Open
scabug opened this issue Nov 5, 2012 · 3 comments
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Nov 5, 2012

// J.java
package foo;

public class J<M> { protected J(M m) { } }

// S.scala
package bar

class SC1 extends foo.J("")
class SC2 extends foo.J[String]("")
% scalac -d out -cp out S.scala 
S.scala:3: error: constructor J in class J cannot be accessed in package bar
 Access to protected constructor J not permitted because
 enclosing package bar is not a subclass of 
 class J in package foo where target is defined
class SC1 extends foo.J("")
          ^
one error found

Compiles in 2.8, regressed somewhere between 2.8 and 2.9. The fact that the type parameter is not inferred is not that big a deal by itself, but it is made much worse by the error message.

Notes: if S and J are in the same package, it compiles. If J is not parameterized, it compiles. If J is instead the equivalent scala class with a protected[foo] constructor, it compiles.

@scabug
Copy link
Author

scabug commented Nov 5, 2012

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

@scabug
Copy link
Author

scabug commented Sep 12, 2015

@khernyo said (edited on Sep 12, 2015 5:35:40 PM UTC):
I believe this doesn't even need a java class to reproduce:

// A.scala
class A[M] protected(m: M)
class B extends A("a")
$ scalac A.scala 
A.scala:4: error: constructor A in class A cannot be accessed in package <empty>
 Access to protected constructor A not permitted because
 enclosing package <empty> is not a subclass of
 class A where target is defined
class B extends A("a")
                ^
one error found

This compiles in 2.8, but not later. It doesn't compile in current dotty either (same error message). On the other hand, specifying the type parameter makes it compile in all of them.

@scabug scabug added the backend label Apr 7, 2017
@scabug scabug added this to the Backlog milestone Apr 7, 2017
snuyanzin added a commit to snuyanzin/flink that referenced this issue Aug 26, 2022
snuyanzin added a commit to snuyanzin/flink that referenced this issue Aug 30, 2022
snuyanzin added a commit to snuyanzin/flink that referenced this issue Sep 1, 2022
snuyanzin added a commit to snuyanzin/flink that referenced this issue Sep 6, 2022
snuyanzin added a commit to snuyanzin/flink that referenced this issue Sep 6, 2022
snuyanzin added a commit to snuyanzin/flink that referenced this issue Sep 7, 2022
snuyanzin added a commit to snuyanzin/flink that referenced this issue Sep 8, 2022
snuyanzin added a commit to snuyanzin/flink that referenced this issue Sep 12, 2022
snuyanzin added a commit to snuyanzin/flink that referenced this issue Sep 12, 2022
snuyanzin added a commit to snuyanzin/flink that referenced this issue Sep 12, 2022
snuyanzin added a commit to snuyanzin/flink that referenced this issue Sep 15, 2022
snuyanzin added a commit to snuyanzin/flink that referenced this issue Sep 16, 2022
@som-snytt
Copy link

This is why we don't mention tickets or people in commits.

@scala scala deleted a comment from scabug Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants