Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3e58bff

Browse files
dwijnandWojciechMazur
authored andcommittedNov 6, 2024
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]
·
3.6.23.6.2-RC1
1 parent 2238c7a commit 3e58bff

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
@@ -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

Lines changed: 7 additions & 0 deletions
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
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)
Please sign in to comment.