File tree Expand file tree Collapse file tree 4 files changed +27
-2
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 4 files changed +27
-2
lines changed Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff 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 () {
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments