Skip to content
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

Unable to extend protected nested class #21631

Open
WojciechMazur opened this issue Sep 23, 2024 · 3 comments
Open

Unable to extend protected nested class #21631

WojciechMazur opened this issue Sep 23, 2024 · 3 comments
Labels
area:typer compat:java itype:bug regression This worked in a previous version but doesn't anymore

Comments

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Sep 23, 2024

Based on Open CB failure in playframework/playframework - builds logs
Extracted from similar issue: #21599 (comment) - original issue was based on access to private members and was concluded to be working as expected. This case however involves protected members - these AFAIK are considered as public at the bytecode level

Compiler version

3.6.0-RC1-bin-20240915-ad8c21a-NIGHTLY
Bisect points to e7d479f / #21362

If you're not sure what version you're using, run print scalaVersion from sbt
(if you're running scalac manually, use scalac -version instead).

Minimized code

When creating a fix for playframework I've seen one interesting issue in their Netty integration

// AbstractChannel.java
public abstract class AbstractChannel {
    protected AbstractChannel() {}
    protected abstract AbstractUnsafe newUnsafe();
    protected abstract class AbstractUnsafe {
        public abstract void connect();
    }
}
// test.scala
class Channel extends AbstractChannel() {
  override def newUnsafe(): AbstractChannel#AbstractUnsafe = new AbstractUnsafe {
    override def connect(): Unit = ???
  }
}

Output

Fails with

[error] ./test.scala:2:66
[error] Unable to emit reference to constructor AbstractUnsafe in class AbstractUnsafe, class AbstractUnsafe is not accessible in anonymous class AbstractChannel.this.AbstractUnsafe {...}
[error]   override def newUnsafe(): AbstractChannel#AbstractUnsafe = new AbstractUnsafe {
[error]                                                                  ^^^^^^^^^^^^^^
Error compiling project (Scala 3.6.0-RC1-bin-20240922-22ed2fb-NIGHTLY, JVM (17))

Expectation

Should compile

@WojciechMazur WojciechMazur added itype:bug area:typer compat:java regression This worked in a previous version but doesn't anymore labels Sep 23, 2024
@Gedochao
Copy link
Contributor

cc @eed3si9n @hamzaremmal @dwijnand

@dwijnand
Copy link
Member

From the comment

It compiles with --server=false only because it's not actually being compiled - it's not emitting bytecode for Java class

It sounds like at the very least there's a difference between java source parsing and java bytecode parsing.

@Gedochao
Copy link
Contributor

It sounds like at the very least there's a difference between java source parsing and java bytecode parsing.

Scala CLI currently doesn't support Scala/Java mixed compilation with --server=false.
Refer to:

So it's unrelated, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typer compat:java itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

No branches or pull requests

3 participants