From 09e96e2f08bbfa743fb3184be6ff82421bd62303 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 31 Oct 2024 12:43:30 +0000 Subject: [PATCH] Fix Java parsing of annotations on qualified types According to [#1][#1] this is valid syntax: java.lang.@NonNull String [#1]: https://checkerframework.org/jsr308/specification/java-annotation-design.html#qualified-type-syntax --- .../dotty/tools/dotc/parsing/JavaParsers.scala | 1 + tests/pos/i21319/Foo.java | 8 ++++++++ tests/pos/i21319/Test.scala | 3 +++ tests/pos/i21319/Valid.java | 17 +++++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 tests/pos/i21319/Foo.java create mode 100644 tests/pos/i21319/Test.scala create mode 100644 tests/pos/i21319/Valid.java diff --git a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala index 8a9eca2c1e67..fe797c66d104 100644 --- a/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/JavaParsers.scala @@ -298,6 +298,7 @@ object JavaParsers { } while (in.token == DOT) { in.nextToken() + annotations() t = typeArgs(atSpan(t.span.start, in.offset)(typeSelect(t, ident()))) } convertToTypeId(t) diff --git a/tests/pos/i21319/Foo.java b/tests/pos/i21319/Foo.java new file mode 100644 index 000000000000..1240d014b7e7 --- /dev/null +++ b/tests/pos/i21319/Foo.java @@ -0,0 +1,8 @@ +package app; + +import java.util.Optional; +import lib.*; + +public class Foo { + private java.util.@lib.Valid Optional userId; +} diff --git a/tests/pos/i21319/Test.scala b/tests/pos/i21319/Test.scala new file mode 100644 index 000000000000..a85c8f461aab --- /dev/null +++ b/tests/pos/i21319/Test.scala @@ -0,0 +1,3 @@ +package app + +class Test diff --git a/tests/pos/i21319/Valid.java b/tests/pos/i21319/Valid.java new file mode 100644 index 000000000000..17e0e1173726 --- /dev/null +++ b/tests/pos/i21319/Valid.java @@ -0,0 +1,17 @@ +package lib; + +import static java.lang.annotation.ElementType.CONSTRUCTOR; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.TYPE_USE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Target({ METHOD, FIELD, CONSTRUCTOR, PARAMETER, TYPE_USE }) +@Retention(RUNTIME) +@Documented +public @interface Valid {}