Bug 563186 - [15] Record - override annotation for accessors
Change-Id: I78d975191af0f7042fc3b8f79727d126a8976c72
Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
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 a09b58f..d7d8f04 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
@@ -7381,4 +7381,88 @@
new String[] {"--enable-preview"},
customOptions);
}
+ public void testBug563186_01() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private record Point(int myInt){\n"+
+ " @Override\n" +
+ " public int myInt(){\n"+
+ " return this.myInt;\n" +
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(0);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug563186_02() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private record Point(int myInt){\n"+
+ " public int myInt(){\n"+
+ " return this.myInt;\n" +
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(0);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "0");
+ }
+ public void testBug563186_03() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private record Point(int myInt){\n"+
+ " @Override\n" +
+ " public int myInt(int i){\n"+
+ " return this.myInt;\n" +
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(0);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "----------\n" +
+ "1. WARNING in X.java (at line 2)\n" +
+ " private record Point(int myInt){\n" +
+ " ^^^^^\n" +
+ "The type X.Point is never used locally\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " public int myInt(int i){\n" +
+ " ^^^^^^^^^^^^\n" +
+ "The method myInt(int) of type X.Point must override or implement a supertype method\n" +
+ "----------\n",
+ null,
+ true,
+ new String[] {"--enable-preview"},
+ getCompilerOptions());
+ }
+ public void testBug563186_04() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " private record Point(int myInt){\n"+
+ " public int myInt(int i){\n"+
+ " return this.myInt;\n" +
+ " }\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(0);\n"+
+ " }\n"+
+ "}\n"
+ },
+ "0");
+ }
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
index 86d5f90..2483c2c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
@@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
* Contributors:
* IBM Corporation - initial API and implementation
* Stephan Herrmann - Contributions for
@@ -279,7 +283,8 @@
// check @Override annotation
final CompilerOptions compilerOptions = this.scope.compilerOptions();
checkOverride: {
- if (this.binding == null) break checkOverride;
+ // For a record component accessor method, don't bother with checking for override (JLS 15 9.6.4.4)
+ if (this.binding == null || recordComponent != null) break checkOverride;
long complianceLevel = compilerOptions.complianceLevel;
if (complianceLevel < ClassFileConstants.JDK1_5) break checkOverride;
int bindingModifiers = this.binding.modifiers;