Skip to content

Commit

Permalink
Set privateWithin when creating java inner classes
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Oct 31, 2024
1 parent 17dadf7 commit 282f8d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ object SymbolLoaders {
*/
def enterClassAndModule(
owner: Symbol, name: PreName, completer: SymbolLoader,
flags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(using Context): Unit = {
flags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(using Context): (Symbol, Symbol) = {
val clazz = enterClass(owner, name, completer, flags, scope)
val module = enterModule(
owner, name, completer,
modFlags = flags.toTermFlags & RetainedModuleValFlags,
clsFlags = flags.toTypeFlags & RetainedModuleClassFlags,
scope = scope)
(clazz, module)
}

/** Enter all toplevel classes and objects in file `src` into package `owner`, provided
Expand Down
16 changes: 10 additions & 6 deletions compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,12 @@ class ClassfileParser(
classRoot.setFlag(sflags)
moduleRoot.setFlag(Flags.JavaDefined | Flags.ModuleClassCreationFlags)

val jflags1 = innerClasses.get(currentClassName.toString).fold(jflags: Int)(_.jflags)
val privateWithin = getPrivateWithin(jflags1)
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)
Expand Down Expand Up @@ -1059,13 +1059,17 @@ class ClassfileParser(
*/
private def enterOwnInnerClasses()(using Context, DataReader): Unit = {
def enterClassAndModule(entry: InnerClassEntry, file: AbstractFile, jflags: Int) =
SymbolLoaders.enterClassAndModule(
val (cls, mod) = SymbolLoaders.enterClassAndModule(
getOwner(jflags),
entry.originalName,
new ClassfileLoader(file),
classTranslation.flags(jflags),
getScope(jflags))

val privateWithin = getPrivateWithin(jflags)
cls.setPrivateWithin(privateWithin)
mod.setPrivateWithin(privateWithin)

for entry <- innerClasses.valuesIterator do
// create a new class member for immediate inner classes
if entry.outer.name == currentClassName then
Expand Down

0 comments on commit 282f8d3

Please sign in to comment.