File tree 4 files changed +31
-3
lines changed
test/dotty/tools/dotc/reporting
4 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -2496,8 +2496,7 @@ object Parsers {
2496
2496
}
2497
2497
else if (! isStatSep && (in.token != CASE )) {
2498
2498
exitOnError = mustStartStat
2499
- val addendum = if (isModifier) " (no modifiers allowed here)" else " "
2500
- syntaxErrorOrIncomplete(" illegal start of statement" + addendum)
2499
+ syntaxErrorOrIncomplete(IllegalStartOfStatement (isModifier))
2501
2500
}
2502
2501
acceptStatSepUnlessAtEnd(CASE )
2503
2502
}
Original file line number Diff line number Diff line change @@ -109,7 +109,8 @@ public enum ErrorMessageID {
109
109
OnlyFunctionsCanBeFollowedByUnderscoreID ,
110
110
MissingEmptyArgumentListID ,
111
111
DuplicateNamedTypeParameterID ,
112
- UndefinedNamedTypeParameterID
112
+ UndefinedNamedTypeParameterID ,
113
+ IllegalStartOfStatementID
113
114
;
114
115
115
116
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -1879,4 +1879,13 @@ object messages {
1879
1879
val msg = hl " Type parameter $undefinedName is undefined. Expected one of ${definedNames.map(_.show).mkString(" , " )}. "
1880
1880
val explanation = " "
1881
1881
}
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
+ }
1882
1891
}
Original file line number Diff line number Diff line change @@ -1132,4 +1132,23 @@ class ErrorMessagesTests extends ErrorMessagesTest {
1132
1132
assertEquals(tpParams, l2.map(_.show))
1133
1133
1134
1134
}
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
+ }
1135
1154
}
You can’t perform that action at this time.
0 commit comments