From 07dce3f9f1065b2bb4de9d0aa39aa69d5eebd40e Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Wed, 25 Sep 2024 21:31:49 +0100 Subject: [PATCH] Tighten java annot value parsing --- .../dotty/tools/dotc/parsing/JavaParsers.scala | 4 ++-- tests/pos/i20026/J.java | 4 ++++ tests/pos/i20026/S.scala | 1 + tests/pos/i20026/TestInstance.java | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i20026/J.java create mode 100644 tests/pos/i20026/S.scala create mode 100644 tests/pos/i20026/TestInstance.java diff --git a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala index 79282b0e5223..8a9eca2c1e67 100644 --- a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala @@ -369,8 +369,8 @@ object JavaParsers { def annotation(): Option[Tree] = { def classOrId(): Tree = val id = qualId() - if in.lookaheadToken == CLASS then - in.nextToken() + if in.token == DOT && in.lookaheadToken == CLASS then + accept(DOT) accept(CLASS) TypeApply( Select( diff --git a/tests/pos/i20026/J.java b/tests/pos/i20026/J.java new file mode 100644 index 000000000000..e950024ed913 --- /dev/null +++ b/tests/pos/i20026/J.java @@ -0,0 +1,4 @@ +package p; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class J { } diff --git a/tests/pos/i20026/S.scala b/tests/pos/i20026/S.scala new file mode 100644 index 000000000000..7da04d6b6bbe --- /dev/null +++ b/tests/pos/i20026/S.scala @@ -0,0 +1 @@ +class S diff --git a/tests/pos/i20026/TestInstance.java b/tests/pos/i20026/TestInstance.java new file mode 100644 index 000000000000..8db79ad88d89 --- /dev/null +++ b/tests/pos/i20026/TestInstance.java @@ -0,0 +1,15 @@ +package p; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +public @interface TestInstance { + enum Lifecycle { PER_CLASS, PER_METHOD; } + Lifecycle value(); +}