Skip to content

Commit 368fc5b

Browse files
danielyliallanrenucci
authored andcommitted
Fix position error in annotation parameter list parsing
Prior to this commit, an annotation with one or more parameter lists would have incorrect positions attached to each parameter list. For example, the annotation @foo("bar") would have the erroneous position `<4..10>` attached to its `Apply` node instead of the correct position `<4..11>`. This was caused by forget- ting to take into account the closing parenthesis.
1 parent 9c73b0b commit 368fc5b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,9 @@ object Parsers {
14931493
}
14941494
}
14951495
if (in.token == LPAREN && (!inClassConstrAnnots || isLegalAnnotArg))
1496-
parArgumentExprss(Apply(fn, parArgumentExprs()))
1496+
parArgumentExprss(
1497+
atPos(in.offset) { Apply(fn, parArgumentExprs()) }
1498+
)
14971499
else fn
14981500
}
14991501

compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ class SyntaxHighlightingTests extends DottyTest {
6565
@Test
6666
def annotations = {
6767
test("@deprecated class Foo", "<T|@deprecated> <K|class> <T|Foo>")
68-
// test("@Test(\"Hello\") class Foo", "<T|@Test(\"Hello\")> <K|class> <T|Foo>") // FIXME
68+
test("@Test() class Foo", "<T|@Test()> <K|class> <T|Foo>")
69+
test("@Test(\"Hello\") class Foo", "<T|@Test(\"Hello\")> <K|class> <T|Foo>")
70+
test("@Test(\"Hello\")(\"World\") class Foo", "<T|@Test(\"Hello\")(\"World\")> <K|class> <T|Foo>")
6971
test("@annotation.tailrec def foo = 1", "<T|@annotation.tailrec> <K|def> <V|foo> = <L|1>")
7072
}
7173

0 commit comments

Comments
 (0)