mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-12 00:43:14 +00:00
8372382: Invalid RuntimeVisibleTypeAnnotations for compact record constructor
Reviewed-by: liach
This commit is contained in:
parent
4f83d211d1
commit
94de8982f9
@ -4421,12 +4421,13 @@ public class JavacParser implements Parser {
|
|||||||
JCMethodDecl methDef = (JCMethodDecl) def;
|
JCMethodDecl methDef = (JCMethodDecl) def;
|
||||||
if (methDef.name == names.init && methDef.params.isEmpty() && (methDef.mods.flags & Flags.COMPACT_RECORD_CONSTRUCTOR) != 0) {
|
if (methDef.name == names.init && methDef.params.isEmpty() && (methDef.mods.flags & Flags.COMPACT_RECORD_CONSTRUCTOR) != 0) {
|
||||||
ListBuffer<JCVariableDecl> tmpParams = new ListBuffer<>();
|
ListBuffer<JCVariableDecl> tmpParams = new ListBuffer<>();
|
||||||
|
TreeCopier<Void> copier = new TreeCopier<>(F);
|
||||||
for (JCVariableDecl param : headerFields) {
|
for (JCVariableDecl param : headerFields) {
|
||||||
tmpParams.add(F.at(param)
|
tmpParams.add(F.at(param)
|
||||||
// we will get flags plus annotations from the record component
|
// we will get flags plus annotations from the record component
|
||||||
.VarDef(F.Modifiers(Flags.PARAMETER | Flags.GENERATED_MEMBER | Flags.MANDATED | param.mods.flags & Flags.VARARGS,
|
.VarDef(F.Modifiers(Flags.PARAMETER | Flags.GENERATED_MEMBER | Flags.MANDATED | param.mods.flags & Flags.VARARGS,
|
||||||
param.mods.annotations),
|
copier.copy(param.mods.annotations)),
|
||||||
param.name, param.vartype, null));
|
param.name, copier.copy(param.vartype), null));
|
||||||
}
|
}
|
||||||
methDef.params = tmpParams.toList();
|
methDef.params = tmpParams.toList();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,6 +78,17 @@ public class TypeAnnotationsPositionsOnRecords {
|
|||||||
record Record6(String t1, @Nullable String t2) {
|
record Record6(String t1, @Nullable String t2) {
|
||||||
public Record6 {}
|
public Record6 {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Test2 {
|
||||||
|
@Target(ElementType.TYPE_USE)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface Anno {}
|
||||||
|
|
||||||
|
class Foo {}
|
||||||
|
record Record7(Test2.@Anno Foo foo) {
|
||||||
|
public Record7 {} // compact constructor
|
||||||
|
}
|
||||||
|
}
|
||||||
""";
|
""";
|
||||||
|
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) throws Exception {
|
||||||
@ -100,6 +111,8 @@ public class TypeAnnotationsPositionsOnRecords {
|
|||||||
"Record5.class").toUri()), 1);
|
"Record5.class").toUri()), 1);
|
||||||
checkClassFile(new File(Paths.get(System.getProperty("user.dir"),
|
checkClassFile(new File(Paths.get(System.getProperty("user.dir"),
|
||||||
"Record6.class").toUri()), 1);
|
"Record6.class").toUri()), 1);
|
||||||
|
checkClassFile(new File(Paths.get(System.getProperty("user.dir"),
|
||||||
|
"Test2$Record7.class").toUri()), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void compileTestClass() throws Exception {
|
void compileTestClass() throws Exception {
|
||||||
@ -110,6 +123,7 @@ public class TypeAnnotationsPositionsOnRecords {
|
|||||||
|
|
||||||
void checkClassFile(final File cfile, int... taPositions) throws Exception {
|
void checkClassFile(final File cfile, int... taPositions) throws Exception {
|
||||||
ClassModel classFile = ClassFile.of().parse(cfile.toPath());
|
ClassModel classFile = ClassFile.of().parse(cfile.toPath());
|
||||||
|
System.err.println("-----------loading " + cfile.getPath());
|
||||||
int accessorPos = 0;
|
int accessorPos = 0;
|
||||||
int checkedAccessors = 0;
|
int checkedAccessors = 0;
|
||||||
for (MethodModel method : classFile.methods()) {
|
for (MethodModel method : classFile.methods()) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user