Skip to content

Fix #3471: Avoid wrong flag kind when desugaring module definitions #3486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ object desugar {
val clsName = moduleName.moduleClassName
val clsRef = Ident(clsName)
val modul = ValDef(moduleName, clsRef, New(clsRef, Nil))
.withMods(mods | ModuleCreationFlags | mods.flags & AccessFlags)
.withMods(mods.toTermFlags & RetainedModuleValFlags | ModuleValCreationFlags)
.withPos(mdef.pos.startPos)
val ValDef(selfName, selfTpt, _) = impl.self
val selfMods = impl.self.mods
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ object Flags {
final val RetainedTypeArgFlags = VarianceFlags | Protected | Local

/** Modules always have these flags set */
final val ModuleCreationFlags = ModuleVal | Lazy | Final | Stable
final val ModuleValCreationFlags = ModuleVal | Lazy | Final | Stable

/** Module classes always have these flags set */
final val ModuleClassCreationFlags = ModuleClass | Final
Expand Down Expand Up @@ -503,7 +503,7 @@ object Flags {
/** Flags that can apply to a module val */
final val RetainedModuleValFlags: FlagSet = RetainedModuleValAndClassFlags |
Override | Final | Method | Implicit | Lazy |
Accessor | AbsOverride | Stable | Captured | Synchronized
Accessor | AbsOverride | Stable | Captured | Synchronized | Inline

/** Flags that can apply to a module class */
final val RetainedModuleClassFlags: FlagSet = RetainedModuleValAndClassFlags | ImplClass | Enum
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ trait Symbols { this: Context =>
modcls, owner, modclsName, modclsFlags,
infoFn(module, modcls), privateWithin)
val mdenot = SymDenotation(
module, owner, name, modFlags | ModuleCreationFlags,
module, owner, name, modFlags | ModuleValCreationFlags,
if (cdenot.isCompleted) TypeRef.withSym(owner.thisType, modcls, modclsName)
else new ModuleCompleter(modcls))
module.denot = mdenot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
if (lacksDefinition && tag != PARAM) flags |= Deferred
if (tag == DEFDEF) flags |= Method
if (givenFlags is Module)
flags = flags | (if (tag == VALDEF) ModuleCreationFlags else ModuleClassCreationFlags)
flags = flags | (if (tag == VALDEF) ModuleValCreationFlags else ModuleClassCreationFlags)
if (ctx.owner.isClass) {
if (tag == TYPEPARAM) flags |= Param
else if (tag == PARAM) flags |= ParamAccessor
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class Namer { typer: Typer =>
def preExisting = ctx.effectiveScope.lookup(name)
if (ctx.owner is PackageClass)
if (preExisting.isDefinedInCurrentRun)
errorName(s"${preExisting.showLocated} has already been compiled\nonce during this run")
errorName(s"${preExisting.showLocated} has already been compiled once during this run")
else name
else
if ((!ctx.owner.isClass || name.isTypeName) && preExisting.exists)
Expand Down
1 change: 1 addition & 0 deletions tests/pos/i3471.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sealed object Fun
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also print a warning saying that the modifier is useless here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do it for final either. If we solve it we should solve it for both at the same time. But not that scalac does not warn for final object either.