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][modified]
  • Loading branch information
WojciechMazur committed Dec 4, 2024
1 parent 54c9ce7 commit 023d0a2
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 @@ -48,19 +48,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, assocFile = completer.sourceFileOrNull)
flags: FlagSet = EmptyFlags, scope: Scope = EmptyScope, privateWithin: Symbol = NoSymbol,
)(using Context): Symbol = {
val cls = newClassSymbol(owner, name.toTypeName.unmangleClassName.decode, flags, completer, privateWithin, assocFile = completer.sourceFileOrNull)
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,
assocFile = completer.sourceFileOrNull)
enterNew(owner, module, completer, scope)
enterNew(owner, module.moduleClass, completer, scope)
Expand Down Expand Up @@ -100,14 +104,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 @@ -884,17 +884,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 023d0a2

Please sign in to comment.