Skip to content

Commit

Permalink
Fix extending protected nested java classes
Browse files Browse the repository at this point in the history
PR 21362 added an accessibility fix to Erasure, but that revealed a
mistake in determining the accessibility of inner java classes, which
I'm now fixing.
dwijnand committed Oct 30, 2024
1 parent dd37f07 commit 17dadf7
Showing 6 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -401,7 +401,8 @@ class ClassfileParser(
classRoot.setFlag(sflags)
moduleRoot.setFlag(Flags.JavaDefined | Flags.ModuleClassCreationFlags)

val privateWithin = getPrivateWithin(jflags)
val jflags1 = innerClasses.get(currentClassName.toString).fold(jflags: Int)(_.jflags)
val privateWithin = getPrivateWithin(jflags1)

classRoot.setPrivateWithin(privateWithin)
moduleRoot.setPrivateWithin(privateWithin)
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/dotc/printing/Formatting.scala
Original file line number Diff line number Diff line change
@@ -109,6 +109,13 @@ object Formatting {
case Atoms.Range(lo, hi) => CtxShow(s"Range(${toStr(lo.toList)}, ${toStr(hi.toList)})")
end given

given Show[ast.untpd.Modifiers] with
def show(x: ast.untpd.Modifiers) =
CtxShow(s"Modifiers(${toStr(x.flags)}, ${toStr(x.privateWithin)}, ${toStr(x.annotations)}, ${toStr(x.mods)})")

given Show[ast.untpd.Mod] with
def show(x: ast.untpd.Mod) = CtxShow(s"Mod(${toStr(x.flags)})")

given Show[Showable] = ShowAny
given Show[Shown] = ShowAny
given Show[Int] = ShowAny
7 changes: 7 additions & 0 deletions tests/pos/i21631_joint/AbstractChannel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public abstract class AbstractChannel {
protected AbstractChannel() {}
protected abstract AbstractUnsafe newUnsafe();
protected abstract class AbstractUnsafe {
public abstract void connect();
}
}
5 changes: 5 additions & 0 deletions tests/pos/i21631_joint/i21631.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Channel extends AbstractChannel() {
override def newUnsafe(): AbstractChannel#AbstractUnsafe = new AbstractUnsafe {
override def connect(): Unit = ???
}
}
7 changes: 7 additions & 0 deletions tests/pos/i21631_separ/AbstractChannel_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public abstract class AbstractChannel_1 {
protected AbstractChannel_1() {}
protected abstract AbstractUnsafe newUnsafe();
protected abstract class AbstractUnsafe {
public abstract void connect();
}
}
5 changes: 5 additions & 0 deletions tests/pos/i21631_separ/i21631_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Channel extends AbstractChannel_1() {
override def newUnsafe(): AbstractChannel_1#AbstractUnsafe = new AbstractUnsafe {
override def connect(): Unit = ???
}
}

0 comments on commit 17dadf7

Please sign in to comment.