Skip to content

Commit e598b4b

Browse files
committed
Fix error position and msg for expression expected
1 parent 845fd59 commit e598b4b

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ object Parsers {
275275
/** If at end of file, issue an incompleteInputError.
276276
* Otherwise issue a syntax error and skip to next safe point.
277277
*/
278-
def syntaxErrorOrIncomplete(msg: => Message): Unit =
278+
def syntaxErrorOrIncomplete(msg: => Message, offset: Int = in.offset): Unit =
279279
if (in.token == EOF) incompleteInputError(msg)
280280
else {
281-
syntaxError(msg)
281+
syntaxError(msg, offset)
282282
skip()
283283
lastErrorOffset = in.offset
284-
} // DEBUG
284+
}
285285

286286
/** Consume one token of the specified type, or
287287
* signal an error if it is not there.
@@ -1456,7 +1456,7 @@ object Parsers {
14561456
case _ =>
14571457
if (isLiteral) literal()
14581458
else {
1459-
syntaxErrorOrIncomplete(IllegalStartSimpleExpr(tokenString(in.token)))
1459+
syntaxErrorOrIncomplete(IllegalStartSimpleExpr(tokenString(in.token)), in.lastOffset)
14601460
errorTermTree
14611461
}
14621462
}

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -569,19 +569,9 @@ object messages {
569569
case class IllegalStartSimpleExpr(illegalToken: String)(implicit ctx: Context)
570570
extends Message(IllegalStartSimpleExprID) {
571571
val kind: String = "Syntax"
572-
val msg: String = "Illegal start of simple expression"
572+
val msg: String = "expression expected"
573573
val explanation: String = {
574-
hl"""|An expression yields a value. In the case of the simple expression, this error
575-
|commonly occurs when there's a missing parenthesis or brace. The reason being
576-
|that a simple expression is one of the following:
577-
|
578-
|- Block
579-
|- Expression in parenthesis
580-
|- Identifier
581-
|- Object creation
582-
|- Literal
583-
|
584-
|which cannot start with ${Red(illegalToken)}."""
574+
hl"""|An expression cannot start with ${Red(illegalToken)}."""
585575
}
586576
}
587577

tests/neg/errpos.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test {
2+
val x = // error: expression expected
3+
val y = 2 // error: ';' expected
4+
}

0 commit comments

Comments
 (0)