Skip to content

Revise #4973: move fix of #4936 into desugar #5723

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 2 commits into from
Jan 19, 2019
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
11 changes: 11 additions & 0 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,17 @@ object desugar {
val impl = mdef.impl
val mods = mdef.mods
def isEnumCase = mods.isEnumCase

def flagSourcePos(flag: FlagSet) = mods.mods.find(_.flags == flag).fold(mdef.sourcePos)(_.sourcePos)

if (mods.is(Abstract))
ctx.error(hl"""$Abstract modifier cannot be used for objects""", flagSourcePos(Abstract))
if (mods.is(Sealed))
ctx.error(hl"""$Sealed modifier is redundant for objects""", flagSourcePos(Sealed))
// Maybe this should be an error; see https://github.com/scala/bug/issues/11094.
if (mods.is(Final) && !mods.is(Synthetic))
ctx.warning(hl"""$Final modifier is redundant for objects""", flagSourcePos(Final))

if (mods is Package)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should fix the crashes in http://dotty-ci.epfl.ch/lampepfl/dotty/9779/5

PackageDef(Ident(moduleName), cpy.ModuleDef(mdef)(nme.PACKAGE, impl).withMods(mods &~ Package) :: Nil)
else if (isEnumCase)
Expand Down
10 changes: 0 additions & 10 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2415,16 +2415,6 @@ object Parsers {

def objectDefRest(start: Offset, mods: Modifiers, name: TermName): ModuleDef = {
val template = templateOpt(emptyConstructor)

def flagSpan(flag: FlagSet) = mods.mods.find(_.flags == flag).get.span
if (mods is Abstract)
syntaxError(hl"""${Abstract} modifier cannot be used for objects""", flagSpan(Abstract))
if (mods is Sealed)
syntaxError(hl"""${Sealed} modifier is redundant for objects""", flagSpan(Sealed))
// Maybe this should be an error; see https://github.com/scala/bug/issues/11094.
if (mods is Final)
warning(hl"""${Final} modifier is redundant for objects""", source atSpan flagSpan(Final))

finalizeDef(ModuleDef(name, template), mods, start)
}

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 @@ -270,7 +270,7 @@ class Namer { typer: Typer =>

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