Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2020-10-22 13:59:09 +0000
committerJay Arthanareeswaran2020-10-22 14:33:02 +0000
commit553e15826cc46c11229f17fd6da0fa43ed0055a9 (patch)
treebeb4f390a86fb12770147b5e9e7651ab89b1e68f
parent7e35bbd8b9cc36a449e562c61841f9968ec4bec3 (diff)
downloadeclipse.jdt.core-I20201026-0650.tar.gz
eclipse.jdt.core-I20201026-0650.tar.xz
eclipse.jdt.core-I20201026-0650.zip
Change-Id: I5ef33e0923e9eafc1b3e3c47f57c0d828a1f50b8 Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
-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.java48
-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.java17
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java11
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties1
6 files changed, 73 insertions, 9 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 d631a56642..ff5f727181 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
@@ -1261,6 +1261,7 @@ public void test011_problem_categories() {
expectedProblemAttributes.put("RecordIllegalExplicitFinalFieldAssignInCompactConstructor", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("RecordMissingExplicitConstructorCallInNonCanonicalConstructor", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("RecordIllegalStaticModifierForLocalClassOrInterface", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
+ expectedProblemAttributes.put("RecordIllegalModifierForLocalRecord", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("LocalStaticsIllegalVisibilityModifierForInterfaceLocalType", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("SealedMissingClassModifier", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
expectedProblemAttributes.put("SealedDisAllowedNonSealedModifierInClass", new ProblemAttributes(CategorizedProblem.CAT_PREVIEW_RELATED));
@@ -2308,6 +2309,7 @@ public void test012_compiler_problems_tuning() {
expectedProblemAttributes.put("RecordCannotDefineRecordInLocalType",SKIP);
expectedProblemAttributes.put("RecordMissingExplicitConstructorCallInNonCanonicalConstructor",SKIP);
expectedProblemAttributes.put("RecordIllegalStaticModifierForLocalClassOrInterface", SKIP);
+ expectedProblemAttributes.put("RecordIllegalModifierForLocalRecord", SKIP);
expectedProblemAttributes.put("RecordComponentsCannotHaveModifiers",SKIP);
expectedProblemAttributes.put("RecordIllegalParameterNameInCanonicalConstructor",SKIP);
expectedProblemAttributes.put("RecordIllegalExplicitFinalFieldAssignInCompactConstructor",SKIP);
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 9031689c0d..e3c6a1b251 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
@@ -7878,4 +7878,52 @@ public void testBug566554_04() {
"Type mismatch: cannot convert from Margin to int\n" +
"----------\n");
}
+public void testBug567731_001() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " non-sealed record R() {}\n" +
+ " public static void main(String[] args) {\n" +
+ " sealed record B() { } \n" +
+ " }" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " non-sealed record R() {}\n" +
+ " ^\n" +
+ "Illegal modifier for the record R; only public, private, protected, static, final and strictfp are permitted\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " sealed record B() { } \n" +
+ " ^\n" +
+ "Illegal modifier for the local record B; only final and strictfp are permitted\n" +
+ "----------\n"
+ );
+}
+public void testBug567731_002() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " sealed record R1() {}\n" +
+ " public static void main(String[] args) {\n" +
+ " non-sealed record R2() { } \n" +
+ " }" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 2)\n" +
+ " sealed record R1() {}\n" +
+ " ^^\n" +
+ "Illegal modifier for the record R1; only public, private, protected, static, final and strictfp are permitted\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " non-sealed record R2() { } \n" +
+ " ^^\n" +
+ "Illegal modifier for the local record R2; only final and strictfp are permitted\n" +
+ "----------\n"
+ );
+}
} \ 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 b20ddf0317..1f4172ca27 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
@@ -2355,6 +2355,9 @@ void setSourceStart(int sourceStart);
/** @since 3.24
* @noreference preview feature error */
int RecordIllegalStaticModifierForLocalClassOrInterface = PreviewRelated + 1761;
+ /** @since 3.24
+ * @noreference preview feature error */
+ int RecordIllegalModifierForLocalRecord = PreviewRelated + 1762;
/** @since 3.24
* @noreference preview feature error */
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 72a1921d91..99239907ed 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
@@ -785,19 +785,18 @@ public class ClassScope extends Scope {
modifiers |= ExtraCompilerModifiers.AccSealed;
}
} else if (sourceType.isRecord()) {
+ int UNEXPECTED_MODIFIERS = ExtraCompilerModifiers.AccNonSealed | ExtraCompilerModifiers.AccSealed;
if (isMemberType) {
- final int UNEXPECTED_MODIFIERS = ~(ClassFileConstants.AccPublic | ClassFileConstants.AccPrivate | ClassFileConstants.AccProtected | ClassFileConstants.AccStatic | ClassFileConstants.AccFinal | ClassFileConstants.AccStrictfp);
- if ((realModifiers & UNEXPECTED_MODIFIERS) != 0)
+ final int EXPECTED_MODIFIERS = (ClassFileConstants.AccPublic | ClassFileConstants.AccPrivate | ClassFileConstants.AccProtected | ClassFileConstants.AccStatic | ClassFileConstants.AccFinal | ClassFileConstants.AccStrictfp);
+ if ((realModifiers & ~EXPECTED_MODIFIERS) != 0 || (modifiers & UNEXPECTED_MODIFIERS) != 0)
problemReporter().illegalModifierForInnerRecord(sourceType);
} else if (sourceType.isLocalType()) {
- final int UNEXPECTED_MODIFIERS = ~(ClassFileConstants.AccAbstract | ClassFileConstants.AccFinal | ClassFileConstants.AccStrictfp | ClassFileConstants.AccStatic);
- if ((realModifiers & UNEXPECTED_MODIFIERS) != 0)
- problemReporter().illegalModifierForLocalClass(sourceType);
+ final int EXPECTED_MODIFIERS = (ClassFileConstants.AccFinal | ClassFileConstants.AccStrictfp | ClassFileConstants.AccStatic);
+ if ((realModifiers & ~EXPECTED_MODIFIERS) != 0 || (modifiers & UNEXPECTED_MODIFIERS) != 0)
+ problemReporter().illegalModifierForLocalRecord(sourceType);
} else {
- final int UNEXPECTED_MODIFIERS = ~(ClassFileConstants.AccPublic | ClassFileConstants.AccFinal | ClassFileConstants.AccStrictfp);
- if ((realModifiers & UNEXPECTED_MODIFIERS) != 0
- || (modifiers & ExtraCompilerModifiers.AccNonSealed) != 0
- || (modifiers & ExtraCompilerModifiers.AccSealed) != 0)
+ final int EXPECTED_MODIFIERS = (ClassFileConstants.AccPublic | ClassFileConstants.AccFinal | ClassFileConstants.AccStrictfp);
+ if ((realModifiers & ~EXPECTED_MODIFIERS) != 0 || (modifiers & UNEXPECTED_MODIFIERS) != 0)
problemReporter().illegalModifierForRecord(sourceType);
}
// JLS 14 8.10 : It is a compile-time error if a record declaration has the modifier abstract.
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 35b4fa8ee6..1956d732b6 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
@@ -11577,6 +11577,17 @@ public void switchExpressionsReturnWithinSwitchExpression(ASTNode statement) {
statement.sourceStart,
statement.sourceEnd);
}
+public void illegalModifierForLocalRecord(SourceTypeBinding type) {
+ if (!this.options.enablePreviewFeatures)
+ return;
+ String[] arguments = new String[] {new String(type.sourceName())};
+ this.handle(
+ IProblem.RecordIllegalModifierForLocalRecord,
+ arguments,
+ arguments,
+ type.sourceStart(),
+ type.sourceEnd());
+}
public void illegalModifierForInnerRecord(SourceTypeBinding type) {
if (!this.options.enablePreviewFeatures)
return;
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 7391997932..f2f39b32d5 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
@@ -1057,6 +1057,7 @@
1759 = Illegal explicit assignment of a final field {0} in compact constructor
1760 = A non-canonical constructor must start with an explicit invocation to a constructor
1761 = A local interface, enum or record {0} is implicitly static; cannot have explicit static declaration
+1762 = Illegal modifier for the local record {0}; only final and strictfp are permitted
1765 = Illegal modifier for the local interface {0}; abstract and strictfp are the only modifiers allowed explicitly

Back to the top