Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extending protected nested java classes #21857

Merged
merged 3 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
dwijnand marked this conversation as resolved.
Show resolved Hide resolved
val privateWithin = getPrivateWithin(jflags1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scala 2 sets the privateWithin for inner classes when creating the symbol in enterOwnInnerClasses

https://github.com/scala/scala/blob/v2.13.15/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala#L1055-L1058

Maybe Scala 3 should also do it there?


classRoot.setPrivateWithin(privateWithin)
moduleRoot.setPrivateWithin(privateWithin)
Expand Down
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/dotc/printing/Formatting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)})")
dwijnand marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Down
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 = ???
}
}
Loading