Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trailing comma Ident's span #20445

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
36 changes: 36 additions & 0 deletions tests/neg/i16872.check
Original file line number Diff line number Diff line change
@@ -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`
19 changes: 19 additions & 0 deletions tests/neg/i16872.scala
Original file line number Diff line number Diff line change
@@ -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
)
Loading