Skip to content

Commit 4ecb1f7

Browse files
Merge pull request scala#2897 from lorandszakacs/errmsg/lorandszakacs_parser_1703
scala#1589 Move duplicate qualified modifier error to new format
2 parents d7faafa + 027b94f commit 4ecb1f7

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ object Parsers {
17001700
def accessQualifierOpt(mods: Modifiers): Modifiers =
17011701
if (in.token == LBRACKET) {
17021702
if ((mods is Local) || mods.hasPrivateWithin)
1703-
syntaxError("duplicate private/protected qualifier")
1703+
syntaxError(DuplicatePrivateProtectedQualifier())
17041704
inBrackets {
17051705
if (in.token == THIS) { in.nextToken(); mods | Local }
17061706
else mods.withPrivateWithin(ident().toTypeName)

compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public enum ErrorMessageID {
9393
ModifiersNotAllowedID,
9494
WildcardOnTypeArgumentNotAllowedOnNewID,
9595
ImplicitFunctionTypeNeedsNonEmptyParameterListID,
96-
WrongNumberOfParametersID
96+
WrongNumberOfParametersID,
97+
DuplicatePrivateProtectedQualifierID,
9798
;
9899

99100
public int errorNumber() {

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,4 +1694,12 @@ object messages {
16941694
val explanation = ""
16951695
}
16961696

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

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,4 +910,20 @@ class ErrorMessagesTests extends ErrorMessagesTest {
910910

911911
assertEquals(err, WrongNumberOfParameters(1))
912912
}
913+
914+
@Test def duplicatePrivateProtectedQualifier =
915+
checkMessagesAfter("frontend") {
916+
"""class Test {
917+
| private[Test] protected[this] def foo(): Unit = ()
918+
|} """.stripMargin
919+
}
920+
.expect { (ictx, messages) =>
921+
implicit val ctx: Context = ictx
922+
val defn = ictx.definitions
923+
924+
assertMessageCount(1, messages)
925+
val err :: Nil = messages
926+
927+
assertEquals(DuplicatePrivateProtectedQualifier(), err)
928+
}
913929
}

0 commit comments

Comments
 (0)