File tree Expand file tree Collapse file tree 4 files changed +34
-3
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 4 files changed +34
-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 = 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,15 @@ 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
+ private val addendum = if (isModifier) " (no modifiers allowed here)" else " "
1886
+ val msg = hl " Illegal start of statement $addendum"
1887
+ val explanation = hl """
1888
+ | Expected an import, a statement or an expression at the start of a statement.
1889
+ | For a detailed list of allowed statements, please consult the syntax of BlockStat at http://dotty.epfl.ch/docs/internals/syntax.html#expressions
1890
+ """
1891
+
1892
+ }
1882
1893
}
Original file line number Diff line number Diff line change @@ -1132,4 +1132,24 @@ 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
+ |
1144
+ """ .stripMargin
1145
+ }
1146
+ .expect { (ictx, messages) =>
1147
+ implicit val ctx : Context = ictx
1148
+
1149
+ assertMessageCount(2 , messages)
1150
+ val errWithModifier :: err :: Nil = messages
1151
+
1152
+ assertEquals(IllegalStartOfStatement (isModifier = false ), err)
1153
+ assertEquals(IllegalStartOfStatement (isModifier = true ), errWithModifier)
1154
+ }
1135
1155
}
You can’t perform that action at this time.
0 commit comments