File tree Expand file tree Collapse file tree 4 files changed +31
-3
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 4 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -2496,8 +2496,7 @@ object Parsers {
24962496 }
24972497 else if (! isStatSep && (in.token != CASE )) {
24982498 exitOnError = mustStartStat
2499- val addendum = if (isModifier) " (no modifiers allowed here)" else " "
2500- syntaxErrorOrIncomplete(" illegal start of statement" + addendum)
2499+ syntaxErrorOrIncomplete(IllegalStartOfStatement (isModifier))
25012500 }
25022501 acceptStatSepUnlessAtEnd(CASE )
25032502 }
Original file line number Diff line number Diff line change @@ -109,7 +109,8 @@ public enum ErrorMessageID {
109109 OnlyFunctionsCanBeFollowedByUnderscoreID ,
110110 MissingEmptyArgumentListID ,
111111 DuplicateNamedTypeParameterID ,
112- UndefinedNamedTypeParameterID
112+ UndefinedNamedTypeParameterID ,
113+ IllegalStartOfStatementID
113114 ;
114115
115116 public int errorNumber () {
Original file line number Diff line number Diff line change @@ -1879,4 +1879,13 @@ object messages {
18791879 val msg = hl " Type parameter $undefinedName is undefined. Expected one of ${definedNames.map(_.show).mkString(" , " )}. "
18801880 val explanation = " "
18811881 }
1882+
1883+ case class IllegalStartOfStatement (isModifier : Boolean )(implicit ctx : Context ) extends Message (IllegalStartOfStatementID ) {
1884+ val kind = " Syntax"
1885+ val msg = {
1886+ val addendum = if (isModifier) " : no modifiers allowed here" else " "
1887+ " Illegal start of statement" + addendum
1888+ }
1889+ val explanation = " A statement is either an import, a definition or an expression."
1890+ }
18821891}
Original file line number Diff line number Diff line change @@ -1132,4 +1132,23 @@ class ErrorMessagesTests extends ErrorMessagesTest {
11321132 assertEquals(tpParams, l2.map(_.show))
11331133
11341134 }
1135+
1136+ @ Test def illegalStartOfStatement =
1137+ checkMessagesAfter(" frontend" ) {
1138+ """
1139+ |object Test {
1140+ | { ) }
1141+ | { private ) }
1142+ |}
1143+ """ .stripMargin
1144+ }
1145+ .expect { (ictx, messages) =>
1146+ implicit val ctx : Context = ictx
1147+
1148+ assertMessageCount(2 , messages)
1149+ val errWithModifier :: err :: Nil = messages
1150+
1151+ assertEquals(IllegalStartOfStatement (isModifier = false ), err)
1152+ assertEquals(IllegalStartOfStatement (isModifier = true ), errWithModifier)
1153+ }
11351154}
You can’t perform that action at this time.
0 commit comments