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 #22222

Open
WenjunHuang opened this issue Dec 17, 2024 · 0 comments
Open

Unable to extend protected nested class #22222

WenjunHuang opened this issue Dec 17, 2024 · 0 comments

Comments

@WenjunHuang
Copy link

WenjunHuang commented Dec 17, 2024

Compiler version

3.6.2

Minimized code

Given the following Java class

package com.library;

public abstract class AbstractChannel {
    protected AbstractChannel() {
    }

    protected abstract AbstractUnsafe newUnsafe();

    protected abstract class AbstractUnsafe {
        protected AbstractUnsafe() {}

        public abstract void connect();
    }
}

The following Scala class, located in a different package, extends the above Java class and contains an anonymous inner class.

package com.user
import com.library.AbstractChannel

class Channel extends AbstractChannel() {
  private val myUnsafe: AbstractUnsafe = new AbstractUnsafe {
    override def connect(): Unit = ???
  }

  override def newUnsafe(): AbstractUnsafe = myUnsafe
}

Output

Failed with

[error] 5 |  private val myUnsafe: AbstractUnsafe = new AbstractUnsafe {
[error]   |                                             ^^^^^^^^^^^^^^
[error]   |Unable to emit reference to constructor AbstractUnsafe in class AbstractUnsafe, class AbstractUnsafe is not accessible in anonymous class AbstractChannel.this.AbstractUnsafe {...}
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

Expectation

Should Compile

Possibly related to #21631.

@WenjunHuang WenjunHuang added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 17, 2024
@Gedochao Gedochao added compat:java and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants