Skip to content

Commit d31f32e

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 20f431b commit d31f32e

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
@@ -1447,7 +1447,9 @@ object Parsers {
14471447
}
14481448
}
14491449
if (in.token == LPAREN && (!inClassConstrAnnots || isLegalAnnotArg))
1450-
parArgumentExprss(Apply(fn, parArgumentExprs()))
1450+
parArgumentExprss(
1451+
atPos(in.offset) { Apply(fn, parArgumentExprs()) }
1452+
)
14511453
else fn
14521454
}
14531455

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)