diff options
author | Jay Arthanareeswaran | 2020-08-12 10:15:26 +0000 |
---|---|---|
committer | Jay Arthanareeswaran | 2020-08-12 10:20:31 +0000 |
commit | ce66cc4aee6213b2f86a3d1dfec59d978381bfac (patch) | |
tree | 65b76c6ff252f25cc51c90152a625ab221693264 | |
parent | 0ba0ff5a1b9449f6f9284ceec17a8416913bd368 (diff) | |
download | eclipse.jdt.core-ce66cc4aee6213b2f86a3d1dfec59d978381bfac.tar.gz eclipse.jdt.core-ce66cc4aee6213b2f86a3d1dfec59d978381bfac.tar.xz eclipse.jdt.core-ce66cc4aee6213b2f86a3d1dfec59d978381bfac.zip |
Change-Id: I78d975191af0f7042fc3b8f79727d126a8976c72
Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
2 files changed, 90 insertions, 1 deletions
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 a09b58fdb6..d7d8f047bb 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 @@ public void testBug563182_07() { 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 86d5f9069a..2483c2c4f1 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 @@ public class MethodDeclaration extends AbstractMethodDeclaration { // 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; |