Skip to content

Commit f9a0010

Browse files
dwijnandWojciechMazur
authored andcommitted
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. [Cherry-picked 17dadf7]
1 parent 3febab3 commit f9a0010

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ class ClassfileParser(
226226
classRoot.setFlag(sflags)
227227
moduleRoot.setFlag(Flags.JavaDefined | Flags.ModuleClassCreationFlags)
228228

229-
val privateWithin = getPrivateWithin(jflags)
229+
val jflags1 = innerClasses.get(currentClassName.toString).fold(jflags: Int)(_.jflags)
230+
val privateWithin = getPrivateWithin(jflags1)
230231

231232
classRoot.setPrivateWithin(privateWithin)
232233
moduleRoot.setPrivateWithin(privateWithin)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ object Formatting {
112112
case Atoms.Range(lo, hi) => CtxShow(s"Range(${toStr(lo.toList)}, ${toStr(hi.toList)})")
113113
end given
114114

115+
given Show[ast.untpd.Modifiers] with
116+
def show(x: ast.untpd.Modifiers) =
117+
CtxShow(s"Modifiers(${toStr(x.flags)}, ${toStr(x.privateWithin)}, ${toStr(x.annotations)}, ${toStr(x.mods)})")
118+
119+
given Show[ast.untpd.Mod] with
120+
def show(x: ast.untpd.Mod) = CtxShow(s"Mod(${toStr(x.flags)})")
121+
115122
given Show[Showable] = ShowAny
116123
given Show[Shown] = ShowAny
117124
given Show[Int] = ShowAny
Lines changed: 7 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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+
}
Lines changed: 7 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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)