Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2020-04-17 09:43:23 +0000
committerManoj Palat2020-05-04 06:36:52 +0000
commit0eba4789c2e202afc71eea7237045f82cbcbf2ad (patch)
treee4102eb92f88af5c6024aa2f789c6555fde271a2
parent2f46ebebf9b4524ef55179986f4aea95fdc652c8 (diff)
downloadeclipse.jdt.core-BETA_JAVA14.tar.gz
eclipse.jdt.core-BETA_JAVA14.tar.xz
eclipse.jdt.core-BETA_JAVA14.zip
Bug 562219 - [14] Records - Error not flagged for records in methodBETA_JAVA14
local inner class Change-Id: I154ee820bb5c4dc22e41b0cdc8b8cd8b0b056645
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java2
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java52
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties1
6 files changed, 65 insertions, 0 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
index 5cf6761362..cc3f6ef077 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
@@ -1249,6 +1249,7 @@ public void test011_problem_categories() {
expectedProblemAttributes.put("RecordComponentCannotBeVoid", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("RecordIllegalVararg", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("RecordStaticReferenceToOuterLocalVariable", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordCannotDefineRecordInLocalType", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
StringBuffer failures = new StringBuffer();
StringBuffer correctResult = new StringBuffer(70000);
Field[] fields = (iProblemClass = IProblem.class).getFields();
@@ -2269,6 +2270,7 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("RecordComponentCannotBeVoid", SKIP);
expectedProblemAttributes.put("RecordIllegalVararg", SKIP);
expectedProblemAttributes.put("RecordStaticReferenceToOuterLocalVariable",SKIP);
+ expectedProblemAttributes.put("RecordCannotDefineRecordInLocalType",SKIP);
Map constantNamesIndex = new HashMap();
Field[] fields = JavaCore.class.getFields();
for (int i = 0, length = fields.length; i < length; i++) {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
index fde30d3954..dce97e3d14 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
@@ -2632,4 +2632,56 @@ public void _test562250c() throws IOException, ClassFormatException {
"RecordComponents:\n" +
"Accessors:");
}
+public void testBug562219_001() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public void foo() {\n"+
+ " @SuppressWarnings(\"unused\")\n"+
+ " class Y {\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " class Z {\n"+
+ " record R() {\n"+
+ " \n"+
+ " }\n"+
+ " }\n"+
+ " }\n"+
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " record R() {\n" +
+ " ^\n" +
+ "A record declaration R is not allowed in a local inner class\n" +
+ "----------\n",
+ null,
+ true
+ );
+}
+public void testBug562219_002() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public void foo() {\n"+
+ " @SuppressWarnings(\"unused\")\n"+
+ " class Y {\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " record R() {}\n"+
+ " }\n"+
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " record R() {}\n" +
+ " ^\n" +
+ "A record declaration R is not allowed in a local inner class\n" +
+ "----------\n",
+ null,
+ true
+ );
+}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
index 0126fbc614..4fcbd9715d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java
@@ -2316,6 +2316,9 @@ void setSourceStart(int sourceStart);
/** @since 3.21
* @noreference preview feature error */
int RecordStaticReferenceToOuterLocalVariable= PreviewRelated + 1755;
+ /** @since 3.22
+ * @noreference preview feature error */
+ int RecordCannotDefineRecordInLocalType= PreviewRelated + 1756;
/* records - end */
/* instanceof pattern: */
/** @since 3.21
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java
index 8f01198cb6..54f1d490d5 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java
@@ -500,6 +500,11 @@ public class ClassScope extends Scope {
problemReporter().illegalLocalTypeDeclaration(this.referenceContext);
sourceType.modifiers = 0;
return;
+ } else if (sourceType.isRecord()) {
+ if (enclosingType != null && enclosingType.isLocalType()) {
+ problemReporter().illegalLocalTypeDeclaration(this.referenceContext);
+ return;
+ }
}
if (sourceType.isAnonymousType()) {
if (compilerOptions().complianceLevel < ClassFileConstants.JDK9)
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
index f2f74687a4..959d720b27 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java
@@ -2856,6 +2856,8 @@ public void illegalLocalTypeDeclaration(TypeDeclaration typeDeclaration) {
problemID = IProblem.CannotDefineAnnotationInLocalType;
} else if ((typeDeclaration.modifiers & ClassFileConstants.AccInterface) != 0) {
problemID = IProblem.CannotDefineInterfaceInLocalType;
+ } else if (typeDeclaration instanceof RecordDeclaration) {
+ problemID = IProblem.RecordCannotDefineRecordInLocalType;
}
if (problemID != 0) {
String[] arguments = new String[] {new String(typeDeclaration.name)};
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
index ab874bdb63..76ac8be9d2 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
@@ -1048,6 +1048,7 @@
1753 = void is an invalid type for the component {0} of a record
1754 = The variable argument type {0} of the record {1} must be the last parameter
1755 = Cannot make a static reference to the non-static variable {0} from a local record
+1756 = A record declaration {0} is not allowed in a local inner class
1760 = The pattern variable {0} is not in scope in this location

Back to the top