Skip to content

Commit 7482735

Browse files
authored
Merge pull request #5723 from dotty-staging/fix-#4936-#4973-desugar
Revise #4973: move fix of #4936 into desugar
2 parents 9b74ac1 + 986c2df commit 7482735

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,17 @@ object desugar {
701701
val impl = mdef.impl
702702
val mods = mdef.mods
703703
def isEnumCase = mods.isEnumCase
704+
705+
def flagSourcePos(flag: FlagSet) = mods.mods.find(_.flags == flag).fold(mdef.sourcePos)(_.sourcePos)
706+
707+
if (mods.is(Abstract))
708+
ctx.error(hl"""$Abstract modifier cannot be used for objects""", flagSourcePos(Abstract))
709+
if (mods.is(Sealed))
710+
ctx.error(hl"""$Sealed modifier is redundant for objects""", flagSourcePos(Sealed))
711+
// Maybe this should be an error; see https://github.com/scala/bug/issues/11094.
712+
if (mods.is(Final) && !mods.is(Synthetic))
713+
ctx.warning(hl"""$Final modifier is redundant for objects""", flagSourcePos(Final))
714+
704715
if (mods is Package)
705716
PackageDef(Ident(moduleName), cpy.ModuleDef(mdef)(nme.PACKAGE, impl).withMods(mods &~ Package) :: Nil)
706717
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
@@ -2415,16 +2415,6 @@ object Parsers {
24152415

24162416
def objectDefRest(start: Offset, mods: Modifiers, name: TermName): ModuleDef = {
24172417
val template = templateOpt(emptyConstructor)
2418-
2419-
def flagSpan(flag: FlagSet) = mods.mods.find(_.flags == flag).get.span
2420-
if (mods is Abstract)
2421-
syntaxError(hl"""${Abstract} modifier cannot be used for objects""", flagSpan(Abstract))
2422-
if (mods is Sealed)
2423-
syntaxError(hl"""${Sealed} modifier is redundant for objects""", flagSpan(Sealed))
2424-
// Maybe this should be an error; see https://github.com/scala/bug/issues/11094.
2425-
if (mods is Final)
2426-
warning(hl"""${Final} modifier is redundant for objects""", source atSpan flagSpan(Final))
2427-
24282418
finalizeDef(ModuleDef(name, template), mods, start)
24292419
}
24302420

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class Namer { typer: Typer =>
270270

271271
/** Check that flags are OK for symbol. This is done early to avoid
272272
* catastrophic failure when we create a TermSymbol with TypeFlags, or vice versa.
273-
* A more complete check is done in checkWellformed.
273+
* A more complete check is done in checkWellFormed.
274274
*/
275275
def checkFlags(flags: FlagSet) =
276276
if (flags.isEmpty) flags

0 commit comments

Comments
 (0)