From cd0103b616f46ed3f73eed652f6b76b1ea88e8aa Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 21 May 2024 17:43:11 +0100 Subject: [PATCH] Fix trailing comma Ident's span [Cherry-picked 9b2f624071bb307e975bd6c3e8b4f39137629b78] --- .../dotty/tools/dotc/parsing/Scanners.scala | 5 ++- tests/neg/i16872.check | 36 +++++++++++++++++++ tests/neg/i16872.scala | 19 ++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i16872.check create mode 100644 tests/neg/i16872.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index c6d07f005fbd..494f56f601cf 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -736,7 +736,10 @@ object Scanners { && currentRegion.commasExpected && (token == RPAREN || token == RBRACKET || token == RBRACE || token == OUTDENT) then - () /* skip the trailing comma */ + // encountered a trailing comma + // reset only the lastOffset + // so that the tree's span is correct + lastOffset = prev.lastOffset else reset() case END => diff --git a/tests/neg/i16872.check b/tests/neg/i16872.check new file mode 100644 index 000000000000..2e0f9cf81eda --- /dev/null +++ b/tests/neg/i16872.check @@ -0,0 +1,36 @@ +-- [E006] Not Found Error: tests/neg/i16872.scala:8:6 ------------------------------------------------------------------ +8 | aa, // error + | ^^ + | Not found: aa + | + | longer explanation available when compiling with `-explain` +-- [E006] Not Found Error: tests/neg/i16872.scala:9:6 ------------------------------------------------------------------ +9 | bb, // error + | ^^ + | Not found: bb + | + | longer explanation available when compiling with `-explain` +-- [E006] Not Found Error: tests/neg/i16872.scala:10:6 ----------------------------------------------------------------- +10 | cc, // error + | ^^ + | Not found: cc + | + | longer explanation available when compiling with `-explain` +-- [E006] Not Found Error: tests/neg/i16872.scala:16:6 ----------------------------------------------------------------- +16 | dd, // error + | ^^ + | Not found: dd + | + | longer explanation available when compiling with `-explain` +-- [E006] Not Found Error: tests/neg/i16872.scala:17:6 ----------------------------------------------------------------- +17 | ee, // error + | ^^ + | Not found: ee - did you mean eq? or perhaps ne? + | + | longer explanation available when compiling with `-explain` +-- [E006] Not Found Error: tests/neg/i16872.scala:18:6 ----------------------------------------------------------------- +18 | ff, // error + | ^^ + | Not found: ff + | + | longer explanation available when compiling with `-explain` diff --git a/tests/neg/i16872.scala b/tests/neg/i16872.scala new file mode 100644 index 000000000000..931ea57e1bec --- /dev/null +++ b/tests/neg/i16872.scala @@ -0,0 +1,19 @@ +// Using a checkfile to verify where the carets point to. +// Originally they were pointing to "cc," and "ff," +// including the trailing comma + +class Test: + def t1 = + ( + aa, // error + bb, // error + cc, // error + ) + + def meth(a: Int, b: Int, c: Int) = a + b + c + def t2 = + meth( + dd, // error + ee, // error + ff, // error + )