Skip to content

Commit eabf0ae

Browse files
authored
Merge pull request #215 from scala/backport-lts-3.3-22391
Backport "Fix annotations being not expected in the middle of an array type by java parser" to 3.3 LTS
2 parents 3114488 + 75450da commit eabf0ae

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,16 @@ object JavaParsers {
254254
t
255255
}
256256

257-
def optArrayBrackets(tpt: Tree): Tree =
257+
def optArrayBrackets(tpt: Tree): Tree = {
258+
annotations()
258259
if (in.token == LBRACKET) {
259260
val tpt1 = atSpan(tpt.span.start, in.offset) { arrayOf(tpt) }
260261
in.nextToken()
261262
accept(RBRACKET)
262263
optArrayBrackets(tpt1)
263264
}
264265
else tpt
266+
}
265267

266268
def basicType(): Tree =
267269
atSpan(in.offset) {
@@ -335,7 +337,7 @@ object JavaParsers {
335337
}
336338

337339
def annotations(): List[Tree] = {
338-
var annots = new ListBuffer[Tree]
340+
val annots = new ListBuffer[Tree]
339341
while (in.token == AT) {
340342
in.nextToken()
341343
annotation() match {

tests/pos/i19642/Valid.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package lib;
2+
3+
import static java.lang.annotation.ElementType.CONSTRUCTOR;
4+
import static java.lang.annotation.ElementType.FIELD;
5+
import static java.lang.annotation.ElementType.METHOD;
6+
import static java.lang.annotation.ElementType.PARAMETER;
7+
import static java.lang.annotation.ElementType.TYPE_USE;
8+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
9+
10+
import java.lang.annotation.Documented;
11+
import java.lang.annotation.Retention;
12+
import java.lang.annotation.Target;
13+
14+
@Target({ METHOD, FIELD, CONSTRUCTOR, PARAMETER, TYPE_USE })
15+
@Retention(RUNTIME)
16+
@Documented
17+
public @interface Valid {}

tests/pos/i19642/i19642.java

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package app;
2+
3+
import java.util.Optional;
4+
import lib.*;
5+
6+
public class i19642 {
7+
private String @lib.Valid [] flatArray;
8+
private String @lib.Valid [] @lib.Valid [] nestedArray;
9+
}

0 commit comments

Comments
 (0)