Skip to content

Commit

Permalink
Push java inner class privateWithin setting
Browse files Browse the repository at this point in the history
[Cherry-picked 14e46e8]
  • Loading branch information
dwijnand authored and WojciechMazur committed Nov 6, 2024
1 parent 2e63e61 commit 6ca4c23
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
20 changes: 13 additions & 7 deletions compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,23 @@ 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)
}

/** Enter module with given `name` into scope of `owner`.
*/
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)
Expand Down Expand Up @@ -103,14 +107,16 @@ object SymbolLoaders {
*/
def enterClassAndModule(
owner: Symbol, name: PreName, completer: SymbolLoader,
flags: FlagSet = EmptyFlags, scope: Scope = EmptyScope)(using Context): (Symbol, Symbol) = {
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)
(clazz, module)
scope = scope,
privateWithin = privateWithin,
)
}

/** Enter all toplevel classes and objects in file `src` into package `owner`, provided
Expand Down
17 changes: 7 additions & 10 deletions compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1059,17 +1059,14 @@ class ClassfileParser(
*/
private def enterOwnInnerClasses()(using Context, DataReader): Unit = {
def enterClassAndModule(entry: InnerClassEntry, file: AbstractFile, jflags: Int) =
val (cls, mod) = SymbolLoaders.enterClassAndModule(
getOwner(jflags),
SymbolLoaders.enterClassAndModule(
getOwner(jflags),
entry.originalName,
new ClassfileLoader(file),
classTranslation.flags(jflags),
getScope(jflags))

val privateWithin = getPrivateWithin(jflags)
cls.setPrivateWithin(privateWithin)
mod.setPrivateWithin(privateWithin)
mod.sourceModule.setPrivateWithin(privateWithin)
new ClassfileLoader(file),
classTranslation.flags(jflags),
getScope(jflags),
getPrivateWithin(jflags),
)

for entry <- innerClasses.valuesIterator do
// create a new class member for immediate inner classes
Expand Down

0 comments on commit 6ca4c23

Please sign in to comment.