Skip to content

Commit 1ecf67b

Browse files
committed
Forbid redundant/illegal object flags
Fix #4936.
1 parent 61cba97 commit 1ecf67b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,16 @@ object desugar {
652652
val impl = mdef.impl
653653
val mods = mdef.mods
654654
def isEnumCase = mods.isEnumCase
655+
656+
def forbidFlag(flag: FlagSet, msg: String): Unit =
657+
if (mods is flag)
658+
ctx.error(hl"""${flag} modifier $msg for objects""", mods.mods.find(_.flags == flag).get.pos)
659+
660+
forbidFlag(Abstract, "cannot be used")
661+
for (flag <- List(Sealed, Final)) {
662+
forbidFlag(flag, "is redundant")
663+
}
664+
655665
if (mods is Package)
656666
PackageDef(Ident(moduleName), cpy.ModuleDef(mdef)(nme.PACKAGE, impl).withMods(mods &~ Package) :: Nil)
657667
else if (isEnumCase)

tests/neg/i4936.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
abstract object Foo // error
2+
sealed final abstract case object Bar // error // error // error

0 commit comments

Comments
 (0)