Skip to content

Commit a31d658

Browse files
Backport "Fix trailing comma Ident's span" to 3.5.2 (#21492)
Backports #20445 to the 3.5.2 branch. PR submitted by the release tooling. [skip ci]
2 parents ebb0256 + cd0103b commit a31d658

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,10 @@ object Scanners {
736736
&& currentRegion.commasExpected
737737
&& (token == RPAREN || token == RBRACKET || token == RBRACE || token == OUTDENT)
738738
then
739-
() /* skip the trailing comma */
739+
// encountered a trailing comma
740+
// reset only the lastOffset
741+
// so that the tree's span is correct
742+
lastOffset = prev.lastOffset
740743
else
741744
reset()
742745
case END =>

tests/neg/i16872.check

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
-- [E006] Not Found Error: tests/neg/i16872.scala:8:6 ------------------------------------------------------------------
2+
8 | aa, // error
3+
| ^^
4+
| Not found: aa
5+
|
6+
| longer explanation available when compiling with `-explain`
7+
-- [E006] Not Found Error: tests/neg/i16872.scala:9:6 ------------------------------------------------------------------
8+
9 | bb, // error
9+
| ^^
10+
| Not found: bb
11+
|
12+
| longer explanation available when compiling with `-explain`
13+
-- [E006] Not Found Error: tests/neg/i16872.scala:10:6 -----------------------------------------------------------------
14+
10 | cc, // error
15+
| ^^
16+
| Not found: cc
17+
|
18+
| longer explanation available when compiling with `-explain`
19+
-- [E006] Not Found Error: tests/neg/i16872.scala:16:6 -----------------------------------------------------------------
20+
16 | dd, // error
21+
| ^^
22+
| Not found: dd
23+
|
24+
| longer explanation available when compiling with `-explain`
25+
-- [E006] Not Found Error: tests/neg/i16872.scala:17:6 -----------------------------------------------------------------
26+
17 | ee, // error
27+
| ^^
28+
| Not found: ee - did you mean eq? or perhaps ne?
29+
|
30+
| longer explanation available when compiling with `-explain`
31+
-- [E006] Not Found Error: tests/neg/i16872.scala:18:6 -----------------------------------------------------------------
32+
18 | ff, // error
33+
| ^^
34+
| Not found: ff
35+
|
36+
| longer explanation available when compiling with `-explain`

tests/neg/i16872.scala

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Using a checkfile to verify where the carets point to.
2+
// Originally they were pointing to "cc," and "ff,"
3+
// including the trailing comma
4+
5+
class Test:
6+
def t1 =
7+
(
8+
aa, // error
9+
bb, // error
10+
cc, // error
11+
)
12+
13+
def meth(a: Int, b: Int, c: Int) = a + b + c
14+
def t2 =
15+
meth(
16+
dd, // error
17+
ee, // error
18+
ff, // error
19+
)

0 commit comments

Comments
 (0)