Skip to content

Spurious access error inheriting from a generic Java class with a protected constructor #345

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
retronym opened this issue Mar 25, 2017 · 5 comments

Comments

@retronym
Copy link
Member

⚡ tail sandbox/{Test.java,sub.scala} && printf "\n" && javac -d /tmp sandbox/Test.java && scalac -d /tmp -cp /tmp sandbox/sub.scala
==> sandbox/Test.java <==
package p1;

public class Test {
    protected Test() {}
}
==> sandbox/sub.scala <==
package p2

class C extends p1.Test()

Add a type parameter:

⚡ tail sandbox/{Test.java,sub.scala} && printf "\n" && javac -d /tmp sandbox/Test.java && scalac -d /tmp -cp /tmp sandbox/sub.scala
==> sandbox/Test.java <==
package p1;

public class Test<T> {
    protected Test() {}
}
==> sandbox/sub.scala <==
package p2

class C extends p1.Test()

sandbox/sub.scala:3: error: constructor Test in class Test cannot be accessed in package p2
 Access to protected constructor Test not permitted because
 enclosing package p2 is not a subclass of
 class Test in package p1 where target is defined
class C extends p1.Test()
                   ^
one error found
@lrytz
Copy link
Member

lrytz commented Mar 30, 2017

The error only shows if no type arguments are provided, i.e.,

package p2
class C extends p1.Test[String]()

compiles

@lrytz
Copy link
Member

lrytz commented Mar 30, 2017

Maybe caused by a cycle (just a guess, I didn't look if that's actually the order of events in the typer): to infer the type argument in the supertype (p1.Test[Nothing]) the typer looks at the constructor call Test(), which triggers accessibility checking, which looks at the incomplete supertype.

@paulp
Copy link

paulp commented Apr 2, 2017

Once known as SI-6617.

@paulp
Copy link

paulp commented Apr 2, 2017

And then, in later years, as SI-10122.

@SethTisue
Copy link
Member

closing as duplicate, then. scala/bug#6617, scala/bug#10122

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

4 participants