-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Combines modifiers not allowed with type, and combinations.This also simplifies logic. Adds more detail to explanation #2807
Changes from 3 commits
1145f89
d178ff3
e2edf34
8a187c5
a449b6a
090c6fd
f7d1629
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1648,18 +1648,35 @@ object messages { | |
val explanation = "Method inlining prohibits calling superclass methods, as it may lead to confusion about which super is being called." | ||
} | ||
|
||
case class ModifiersNotAllowed(flags: FlagSet, sort: String)(implicit ctx: Context) | ||
case class ModifiersNotAllowed(flags: FlagSet, printableType: Option[String])(implicit ctx: Context) | ||
extends Message(ModifiersNotAllowedID) { | ||
val kind = "Syntax" | ||
val msg = s"modifier(s) `$flags' not allowed for $sort" | ||
val msg = s"modifier(s) `$flags' not allowed for ${printableType.getOrElse("combination")}" | ||
val explanation = { | ||
val code = "sealed def y: Int = 1" | ||
val first = "sealed def y: Int = 1" | ||
val second = "sealed lazy class z" | ||
hl"""You tried to use a modifier that is inapplicable for the type of item under modification | ||
| | ||
| Here is a list of modifiers and applicable item types | ||
| | ||
| | ||
| Modifier ::= LocalModifier | ||
| AccessModifier | ||
| `override' traits, methods | ||
| LocalModifier ::= `abstract' classes, traits | ||
| `final' classes, traits, methods | ||
| `sealed' classes, traits | ||
| `implicit' variables, methods, classes | ||
| `lazy' values | ||
| AccessModifier ::= (`private' | `protected') [AccessQualifier] methods, classes | ||
| AccessQualifier ::= `[' (id | `this') `]' | ||
| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a copy of the syntax here might be nice, but it'd be better if we could link to the spec (we could open an issue for this instead). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense rather than duplicating maintenance effort |
||
| | ||
|Consider the following example: | ||
|$code | ||
|$first | ||
|In this instance, the modifier 'sealed' is not applicable to the item type 'def' (method) | ||
|$second | ||
|In this instance, the modifier combination is not supported | ||
""" | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this method is only used by
addFlag
, I would nest it in the method like:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely