Skip to content

Commit 17dadf7

Browse files
committed
Fix extending protected nested java classes
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.
1 parent dd37f07 commit 17dadf7

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,8 @@ class ClassfileParser(
401401
classRoot.setFlag(sflags)
402402
moduleRoot.setFlag(Flags.JavaDefined | Flags.ModuleClassCreationFlags)
403403

404-
val privateWithin = getPrivateWithin(jflags)
404+
val jflags1 = innerClasses.get(currentClassName.toString).fold(jflags: Int)(_.jflags)
405+
val privateWithin = getPrivateWithin(jflags1)
405406

406407
classRoot.setPrivateWithin(privateWithin)
407408
moduleRoot.setPrivateWithin(privateWithin)

compiler/src/dotty/tools/dotc/printing/Formatting.scala

+7
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ object Formatting {
109109
case Atoms.Range(lo, hi) => CtxShow(s"Range(${toStr(lo.toList)}, ${toStr(hi.toList)})")
110110
end given
111111

112+
given Show[ast.untpd.Modifiers] with
113+
def show(x: ast.untpd.Modifiers) =
114+
CtxShow(s"Modifiers(${toStr(x.flags)}, ${toStr(x.privateWithin)}, ${toStr(x.annotations)}, ${toStr(x.mods)})")
115+
116+
given Show[ast.untpd.Mod] with
117+
def show(x: ast.untpd.Mod) = CtxShow(s"Mod(${toStr(x.flags)})")
118+
112119
given Show[Showable] = ShowAny
113120
given Show[Shown] = ShowAny
114121
given Show[Int] = ShowAny
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public abstract class AbstractChannel {
2+
protected AbstractChannel() {}
3+
protected abstract AbstractUnsafe newUnsafe();
4+
protected abstract class AbstractUnsafe {
5+
public abstract void connect();
6+
}
7+
}

tests/pos/i21631_joint/i21631.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Channel extends AbstractChannel() {
2+
override def newUnsafe(): AbstractChannel#AbstractUnsafe = new AbstractUnsafe {
3+
override def connect(): Unit = ???
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public abstract class AbstractChannel_1 {
2+
protected AbstractChannel_1() {}
3+
protected abstract AbstractUnsafe newUnsafe();
4+
protected abstract class AbstractUnsafe {
5+
public abstract void connect();
6+
}
7+
}

tests/pos/i21631_separ/i21631_2.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Channel extends AbstractChannel_1() {
2+
override def newUnsafe(): AbstractChannel_1#AbstractUnsafe = new AbstractUnsafe {
3+
override def connect(): Unit = ???
4+
}
5+
}

0 commit comments

Comments
 (0)