Skip to content

Commit fd76897

Browse files
committed
Refix #4936: Move check from Parsers back to Desugar
This follows again the original strategy in 1ecf67b. This check is at the latest possible point: a few lines later, `RetainedModuleValFlags` excludes `Abstract` and `Sealed` while `ModuleValCreationFlags` adds `Final`.
1 parent b5378aa commit fd76897

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,17 @@ object desugar {
700700
val impl = mdef.impl
701701
val mods = mdef.mods
702702
def isEnumCase = mods.isEnumCase
703+
704+
def flagPos(flag: FlagSet) = mods.mods.find(_.flags == flag).get.pos
705+
706+
if (mods.is(Abstract))
707+
ctx.error(hl"""$Abstract modifier cannot be used for objects""", flagPos(Abstract))
708+
if (mods.is(Sealed))
709+
ctx.error(hl"""$Sealed modifier is redundant for objects""", flagPos(Sealed))
710+
// Maybe this should be an error; see https://github.com/scala/bug/issues/11094.
711+
if (mods.is(Final))
712+
ctx.warning(hl"""$Final modifier is redundant for objects""", flagPos(Final))
713+
703714
if (mods is Package)
704715
PackageDef(Ident(moduleName), cpy.ModuleDef(mdef)(nme.PACKAGE, impl).withMods(mods &~ Package) :: Nil)
705716
else if (isEnumCase)

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,16 +2422,6 @@ object Parsers {
24222422

24232423
def objectDefRest(start: Offset, mods: Modifiers, name: TermName): ModuleDef = {
24242424
val template = templateOpt(emptyConstructor)
2425-
2426-
def flagPos(flag: FlagSet) = mods.mods.find(_.flags == flag).get.pos
2427-
if (mods is Abstract)
2428-
syntaxError(hl"""${Abstract} modifier cannot be used for objects""", flagPos(Abstract))
2429-
if (mods is Sealed)
2430-
syntaxError(hl"""${Sealed} modifier is redundant for objects""", flagPos(Sealed))
2431-
// Maybe this should be an error; see https://github.com/scala/bug/issues/11094.
2432-
if (mods is Final)
2433-
warning(hl"""${Final} modifier is redundant for objects""", source atPos flagPos(Final))
2434-
24352425
finalizeDef(ModuleDef(name, template), mods, start)
24362426
}
24372427

0 commit comments

Comments
 (0)