Skip to content

Commit

Permalink
Set privateWithin when creating java inner classes
Browse files Browse the repository at this point in the history
[Cherry-picked 350215d]
  • Loading branch information
dwijnand authored and WojciechMazur committed Nov 6, 2024
1 parent 3e58bff commit 2e63e61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 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
19 changes: 12 additions & 7 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,18 @@ 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,
entry.originalName,
new ClassfileLoader(file),
classTranslation.flags(jflags),
getScope(jflags))

val privateWithin = getPrivateWithin(jflags)
cls.setPrivateWithin(privateWithin)
mod.setPrivateWithin(privateWithin)
mod.sourceModule.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 2e63e61

Please sign in to comment.