Skip to content

#1589 Move duplicate qualified modifier error to new format #2897

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
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ object Parsers {
def accessQualifierOpt(mods: Modifiers): Modifiers =
if (in.token == LBRACKET) {
if ((mods is Local) || mods.hasPrivateWithin)
syntaxError("duplicate private/protected qualifier")
syntaxError(DuplicatePrivateProtectedQualifier())
inBrackets {
if (in.token == THIS) { in.nextToken(); mods | Local }
else mods.withPrivateWithin(ident().toTypeName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public enum ErrorMessageID {
ModifiersNotAllowedID,
WildcardOnTypeArgumentNotAllowedOnNewID,
ImplicitFunctionTypeNeedsNonEmptyParameterListID,
WrongNumberOfParametersID
WrongNumberOfParametersID,
DuplicatePrivateProtectedQualifierID,
;

public int errorNumber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1694,4 +1694,12 @@ object messages {
val explanation = ""
}

case class DuplicatePrivateProtectedQualifier()(implicit ctx: Context)
extends Message(DuplicatePrivateProtectedQualifierID) {
val kind = "Syntax"
val msg = "duplicate private/protected qualifier"
val explanation =
hl"It is not allowed to combine `private` and `protected` modifiers even if they are qualified to different scopes"
}

}
16 changes: 16 additions & 0 deletions compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -910,4 +910,20 @@ class ErrorMessagesTests extends ErrorMessagesTest {

assertEquals(err, WrongNumberOfParameters(1))
}

@Test def duplicatePrivateProtectedQualifier =
checkMessagesAfter("frontend") {
"""class Test {
| private[Test] protected[this] def foo(): Unit = ()
|} """.stripMargin
}
.expect { (ictx, messages) =>
implicit val ctx: Context = ictx
val defn = ictx.definitions

assertMessageCount(1, messages)
val err :: Nil = messages

assertEquals(DuplicatePrivateProtectedQualifier(), err)
}
}