Skip to content

Unable to extend protected nested class #22222

Open
@WenjunHuang

Description

@WenjunHuang

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions