8252307: javac rejects code with annotation applicable to fields
Reviewed-by: darcy
This commit is contained in:
parent
15af276157
commit
5d2e79e2c3
@ -3387,6 +3387,9 @@ public class Check {
|
||||
} else if (target == names.TYPE_PARAMETER) {
|
||||
if (s.kind == TYP && s.type.hasTag(TYPEVAR))
|
||||
applicableTargets.add(names.TYPE_PARAMETER);
|
||||
} else if (target == names.MODULE) {
|
||||
if (s.kind == MDL)
|
||||
applicableTargets.add(names.MODULE);
|
||||
} else
|
||||
return Optional.empty(); // Unknown ElementType. This should be an error at declaration site,
|
||||
// assume applicable.
|
||||
|
@ -3800,7 +3800,8 @@ public class JavacParser implements Parser {
|
||||
for (JCVariableDecl param : headerFields) {
|
||||
tmpParams.add(F.at(param)
|
||||
// we will get flags plus annotations from the record component
|
||||
.VarDef(F.Modifiers(Flags.PARAMETER | param.mods.flags & Flags.VARARGS, param.mods.annotations),
|
||||
.VarDef(F.Modifiers(Flags.PARAMETER | Flags.GENERATED_MEMBER | param.mods.flags & Flags.VARARGS,
|
||||
param.mods.annotations),
|
||||
param.name, param.vartype, null));
|
||||
}
|
||||
methDef.params = tmpParams.toList();
|
||||
|
@ -1,3 +1,4 @@
|
||||
Buggy.java:24:35: compiler.err.intf.expected.here
|
||||
Buggy.java:24:13: compiler.err.cyclic.inheritance: Buggy
|
||||
2 errors
|
||||
Buggy.java:24:1: compiler.err.annotation.type.not.applicable
|
||||
3 errors
|
||||
|
@ -26,7 +26,7 @@
|
||||
/**
|
||||
* RecordCompilationTests
|
||||
*
|
||||
* @test 8250629
|
||||
* @test 8250629 8252307
|
||||
* @summary Negative compilation tests, and positive compilation (smoke) tests for records
|
||||
* @library /lib/combo /tools/lib /tools/javac/lib
|
||||
* @modules
|
||||
@ -1042,6 +1042,12 @@ public class RecordCompilationTests extends CompilationTestCase {
|
||||
"ElementType.TYPE_USE,ElementType.FIELD,ElementType.PARAMETER",
|
||||
"ElementType.TYPE_USE,ElementType.FIELD,ElementType.RECORD_COMPONENT",
|
||||
"ElementType.FIELD,ElementType.TYPE_USE",
|
||||
"ElementType.FIELD,ElementType.CONSTRUCTOR",
|
||||
"ElementType.FIELD,ElementType.LOCAL_VARIABLE",
|
||||
"ElementType.FIELD,ElementType.ANNOTATION_TYPE",
|
||||
"ElementType.FIELD,ElementType.PACKAGE",
|
||||
"ElementType.FIELD,ElementType.TYPE_PARAMETER",
|
||||
"ElementType.FIELD,ElementType.MODULE",
|
||||
"ElementType.METHOD,ElementType.TYPE_USE",
|
||||
"ElementType.PARAMETER,ElementType.TYPE_USE",
|
||||
"ElementType.RECORD_COMPONENT,ElementType.TYPE_USE",
|
||||
@ -1073,7 +1079,7 @@ public class RecordCompilationTests extends CompilationTestCase {
|
||||
/* if FIELD is one of the targets then there must be a declaration annotation applied to the field, apart from
|
||||
* the type annotation
|
||||
*/
|
||||
if (target.contains("FIELD")) {
|
||||
if (target.contains("ElementType.FIELD")) {
|
||||
checkAnno(classFile,
|
||||
(RuntimeAnnotations_attribute)findAttributeOrFail(
|
||||
field.attributes,
|
||||
@ -1084,7 +1090,7 @@ public class RecordCompilationTests extends CompilationTestCase {
|
||||
}
|
||||
|
||||
// lets check now for the type annotation
|
||||
if (target.contains("TYPE_USE")) {
|
||||
if (target.contains("ElementType.TYPE_USE")) {
|
||||
checkTypeAnno(
|
||||
classFile,
|
||||
(RuntimeVisibleTypeAnnotations_attribute)findAttributeOrFail(field.attributes, RuntimeVisibleTypeAnnotations_attribute.class),
|
||||
@ -1099,7 +1105,7 @@ public class RecordCompilationTests extends CompilationTestCase {
|
||||
/* if PARAMETER is one of the targets then there must be a declaration annotation applied to the parameter, apart from
|
||||
* the type annotation
|
||||
*/
|
||||
if (target.contains("PARAMETER")) {
|
||||
if (target.contains("ElementType.PARAMETER")) {
|
||||
checkParameterAnno(classFile,
|
||||
(RuntimeVisibleParameterAnnotations_attribute)findAttributeOrFail(
|
||||
init.attributes,
|
||||
@ -1109,7 +1115,7 @@ public class RecordCompilationTests extends CompilationTestCase {
|
||||
assertAttributeNotPresent(init.attributes, RuntimeVisibleAnnotations_attribute.class);
|
||||
}
|
||||
// let's check now for the type annotation
|
||||
if (target.contains("TYPE_USE")) {
|
||||
if (target.contains("ElementType.TYPE_USE")) {
|
||||
checkTypeAnno(
|
||||
classFile,
|
||||
(RuntimeVisibleTypeAnnotations_attribute) findAttributeOrFail(init.attributes, RuntimeVisibleTypeAnnotations_attribute.class),
|
||||
@ -1123,7 +1129,7 @@ public class RecordCompilationTests extends CompilationTestCase {
|
||||
/* if METHOD is one of the targets then there must be a declaration annotation applied to the accessor, apart from
|
||||
* the type annotation
|
||||
*/
|
||||
if (target.contains("METHOD")) {
|
||||
if (target.contains("ElementType.METHOD")) {
|
||||
checkAnno(classFile,
|
||||
(RuntimeAnnotations_attribute)findAttributeOrFail(
|
||||
accessor.attributes,
|
||||
@ -1133,7 +1139,7 @@ public class RecordCompilationTests extends CompilationTestCase {
|
||||
assertAttributeNotPresent(accessor.attributes, RuntimeVisibleAnnotations_attribute.class);
|
||||
}
|
||||
// let's check now for the type annotation
|
||||
if (target.contains("TYPE_USE")) {
|
||||
if (target.contains("ElementType.TYPE_USE")) {
|
||||
checkTypeAnno(
|
||||
classFile,
|
||||
(RuntimeVisibleTypeAnnotations_attribute)findAttributeOrFail(accessor.attributes, RuntimeVisibleTypeAnnotations_attribute.class),
|
||||
@ -1148,7 +1154,7 @@ public class RecordCompilationTests extends CompilationTestCase {
|
||||
/* if RECORD_COMPONENT is one of the targets then there must be a declaration annotation applied to the
|
||||
* field, apart from the type annotation
|
||||
*/
|
||||
if (target.contains("RECORD_COMPONENT")) {
|
||||
if (target.contains("ElementType.RECORD_COMPONENT")) {
|
||||
checkAnno(classFile,
|
||||
(RuntimeAnnotations_attribute)findAttributeOrFail(
|
||||
record.component_info_arr[0].attributes,
|
||||
@ -1158,7 +1164,7 @@ public class RecordCompilationTests extends CompilationTestCase {
|
||||
assertAttributeNotPresent(record.component_info_arr[0].attributes, RuntimeVisibleAnnotations_attribute.class);
|
||||
}
|
||||
// lets check now for the type annotation
|
||||
if (target.contains("TYPE_USE")) {
|
||||
if (target.contains("ElementType.TYPE_USE")) {
|
||||
checkTypeAnno(
|
||||
classFile,
|
||||
(RuntimeVisibleTypeAnnotations_attribute)findAttributeOrFail(
|
||||
@ -1294,7 +1300,6 @@ public class RecordCompilationTests extends CompilationTestCase {
|
||||
throw new AssertionError("unexpected element kind");
|
||||
}
|
||||
}
|
||||
Assert.check(targetSet.isEmpty(), targetSet.toString());
|
||||
}
|
||||
|
||||
private void checkTypeAnnotations(Element rootElement) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user