diff --git a/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala b/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala index 5690720a1b3f..0f01a687f905 100644 --- a/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -51,8 +51,9 @@ object SymbolLoaders { */ def enterClass( owner: Symbol, name: PreName, completer: SymbolLoader, - flags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(using Context): Symbol = { - val cls = newClassSymbol(owner, name.toTypeName.unmangleClassName.decode, flags, completer, compUnitInfo = completer.compilationUnitInfo) + flags: FlagSet = EmptyFlags, scope: Scope = EmptyScope, privateWithin: Symbol = NoSymbol, + )(using Context): Symbol = { + val cls = newClassSymbol(owner, name.toTypeName.unmangleClassName.decode, flags, completer, privateWithin, compUnitInfo = completer.compilationUnitInfo) enterNew(owner, cls, completer, scope) } @@ -60,10 +61,13 @@ object SymbolLoaders { */ def enterModule( owner: Symbol, name: PreName, completer: SymbolLoader, - modFlags: FlagSet = EmptyFlags, clsFlags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(using Context): Symbol = { + modFlags: FlagSet = EmptyFlags, clsFlags: FlagSet = EmptyFlags, + scope: Scope = EmptyScope, privateWithin: Symbol = NoSymbol, + )(using Context): Symbol = { val module = newModuleSymbol( owner, name.toTermName.decode, modFlags, clsFlags, (module, _) => completer.proxy.withDecls(newScope).withSourceModule(module), + privateWithin, compUnitInfo = completer.compilationUnitInfo) enterNew(owner, module, completer, scope) enterNew(owner, module.moduleClass, completer, scope) @@ -103,13 +107,16 @@ object SymbolLoaders { */ def enterClassAndModule( owner: Symbol, name: PreName, completer: SymbolLoader, - flags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(using Context): Unit = { - val clazz = enterClass(owner, name, completer, flags, scope) + flags: FlagSet = EmptyFlags, scope: Scope = EmptyScope, privateWithin: Symbol = NoSymbol, + )(using Context): Unit = { + val clazz = enterClass(owner, name, completer, flags, scope, privateWithin) val module = enterModule( owner, name, completer, modFlags = flags.toTermFlags & RetainedModuleValFlags, clsFlags = flags.toTypeFlags & RetainedModuleClassFlags, - scope = scope) + scope = scope, + privateWithin = privateWithin, + ) } /** Enter all toplevel classes and objects in file `src` into package `owner`, provided diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala index 9e7b59a0cfac..3af0fc6603d5 100644 --- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala +++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala @@ -403,9 +403,10 @@ class ClassfileParser( val privateWithin = getPrivateWithin(jflags) - classRoot.setPrivateWithin(privateWithin) - moduleRoot.setPrivateWithin(privateWithin) - moduleRoot.sourceModule.setPrivateWithin(privateWithin) + if privateWithin.exists then + classRoot.setPrivateWithin(privateWithin) + moduleRoot.setPrivateWithin(privateWithin) + moduleRoot.sourceModule.setPrivateWithin(privateWithin) for (i <- 0 until in.nextChar) parseMember(method = false) for (i <- 0 until in.nextChar) parseMember(method = true) @@ -1059,11 +1060,13 @@ class ClassfileParser( private def enterOwnInnerClasses()(using Context, DataReader): Unit = { def enterClassAndModule(entry: InnerClassEntry, file: AbstractFile, jflags: Int) = SymbolLoaders.enterClassAndModule( - getOwner(jflags), - entry.originalName, - new ClassfileLoader(file), - classTranslation.flags(jflags), - getScope(jflags)) + getOwner(jflags), + entry.originalName, + new ClassfileLoader(file), + classTranslation.flags(jflags), + getScope(jflags), + getPrivateWithin(jflags), + ) for entry <- innerClasses.valuesIterator do // create a new class member for immediate inner classes diff --git a/compiler/src/dotty/tools/dotc/printing/Formatting.scala b/compiler/src/dotty/tools/dotc/printing/Formatting.scala index a36e6f48533a..14b822b11333 100644 --- a/compiler/src/dotty/tools/dotc/printing/Formatting.scala +++ b/compiler/src/dotty/tools/dotc/printing/Formatting.scala @@ -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 diff --git a/tests/pos/i21631_joint/AbstractChannel.java b/tests/pos/i21631_joint/AbstractChannel.java new file mode 100644 index 000000000000..fbcd04549def --- /dev/null +++ b/tests/pos/i21631_joint/AbstractChannel.java @@ -0,0 +1,7 @@ +public abstract class AbstractChannel { + protected AbstractChannel() {} + protected abstract AbstractUnsafe newUnsafe(); + protected abstract class AbstractUnsafe { + public abstract void connect(); + } +} diff --git a/tests/pos/i21631_joint/i21631.scala b/tests/pos/i21631_joint/i21631.scala new file mode 100644 index 000000000000..c567d75b1375 --- /dev/null +++ b/tests/pos/i21631_joint/i21631.scala @@ -0,0 +1,5 @@ +class Channel extends AbstractChannel() { + override def newUnsafe(): AbstractChannel#AbstractUnsafe = new AbstractUnsafe { + override def connect(): Unit = ??? + } +} diff --git a/tests/pos/i21631_separ/AbstractChannel_1.java b/tests/pos/i21631_separ/AbstractChannel_1.java new file mode 100644 index 000000000000..e89767d6d73e --- /dev/null +++ b/tests/pos/i21631_separ/AbstractChannel_1.java @@ -0,0 +1,7 @@ +public abstract class AbstractChannel_1 { + protected AbstractChannel_1() {} + protected abstract AbstractUnsafe newUnsafe(); + protected abstract class AbstractUnsafe { + public abstract void connect(); + } +} diff --git a/tests/pos/i21631_separ/i21631_2.scala b/tests/pos/i21631_separ/i21631_2.scala new file mode 100644 index 000000000000..89524e333920 --- /dev/null +++ b/tests/pos/i21631_separ/i21631_2.scala @@ -0,0 +1,5 @@ +class Channel extends AbstractChannel_1() { + override def newUnsafe(): AbstractChannel_1#AbstractUnsafe = new AbstractUnsafe { + override def connect(): Unit = ??? + } +}