Skip to content

Commit

Permalink
Honor lastErrorOffset in incompleteInoutError
Browse files Browse the repository at this point in the history
As for the other errors, don't issue an incomplete input error if the
last error offset is the current offset.
  • Loading branch information
odersky committed Mar 18, 2022
1 parent 9cd7006 commit f190103
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 11 deletions.
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,22 @@ object Parsers {

/** Issue an error at current offset that input is incomplete */
def incompleteInputError(msg: Message): Unit =
report.incompleteInputError(msg, source.atSpan(Span(in.offset)))
if in.offset != lastErrorOffset then
report.incompleteInputError(msg, source.atSpan(Span(in.offset)))

/** If at end of file, issue an incompleteInputError.
* Otherwise issue a syntax error and skip to next safe point.
*/
def syntaxErrorOrIncomplete(msg: Message, offset: Int = in.offset): Unit =
if (in.token == EOF) incompleteInputError(msg)
if in.token == EOF then
incompleteInputError(msg)
else
syntaxError(msg, offset)
skip()

def syntaxErrorOrIncomplete(msg: Message, span: Span): Unit =
if (in.token == EOF) incompleteInputError(msg)
if in.token == EOF then
incompleteInputError(msg)
else
syntaxError(msg, span)
skip()
Expand Down
1 change: 0 additions & 1 deletion tests/neg/i2494.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
enum
object // error
// error
1 change: 0 additions & 1 deletion tests/neg/i4373c.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ==> 18b253a4a89a84c5674165c6fc3efafad535eee3.scala <==
object x0 {
def x1[x2 <:_[ // error
// error
2 changes: 1 addition & 1 deletion tests/neg/i4934.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ object Main {

object Foo {
val a = ""); // error: `}` expected but `)` found
}
} // error: eof expected but `}` found
2 changes: 1 addition & 1 deletion tests/neg/i8731a.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ object test:
for
a <- Seq()
end for // error: `yield` or `do` expected
do () // error: expression expected but eof found
do ()
1 change: 0 additions & 1 deletion tests/neg/parser-stability-1.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
object x0 {
x1 match // error
def this // error
// error
1 change: 0 additions & 1 deletion tests/neg/parser-stability-18.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ trait x0 {
class x1 (x1:x0
{
type x1 <: List[x1 <: // error
// error
1 change: 0 additions & 1 deletion tests/neg/parser-stability-19.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ object x0 {
case class x0[](): // error
def x0( ) ] // error
def x0 ( x0:x0 ):x0.type = x1 x0
// error
1 change: 0 additions & 1 deletion tests/neg/parser-stability-2.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
trait x0 {
new _ // error
// error

0 comments on commit f190103

Please sign in to comment.