Skip to content

Commit 187ced3

Browse files
karolchmistallanrenucci
authored andcommitted
Migrate "illegal start of statement" to error message (#3435)
1 parent 22ff8a4 commit 187ced3

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

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

+1-2
Original file line numberDiff line numberDiff 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
}

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

+2-1
Original file line numberDiff line numberDiff 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() {

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

+9
Original file line numberDiff line numberDiff 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
}

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

+19
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)