Skip to content

Commit e8ceb8d

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 a3cc8f7 commit e8ceb8d

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
@@ -1532,7 +1532,9 @@ object Parsers {
15321532
}
15331533
}
15341534
if (in.token == LPAREN && (!inClassConstrAnnots || isLegalAnnotArg))
1535-
parArgumentExprss(Apply(fn, parArgumentExprs()))
1535+
parArgumentExprss(
1536+
atPos(in.offset) { Apply(fn, parArgumentExprs()) }
1537+
)
15361538
else fn
15371539
}
15381540

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)