Skip to content

Unable to extend protected nested class #21631

Closed
@WojciechMazur

Description

@WojciechMazur

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions