Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2020-11-19 01:03:05 +0000
committerManoj Palat2020-11-20 03:55:52 +0000
commit494515e0d4dc5b9242fa3b7ba806ab9688802431 (patch)
tree8a9b486d25fc1e8c783c5478e1f904eb0cea8746
parentd11a339be174c8495f37fcac04eba762110bab98 (diff)
downloadeclipse.jdt.core-494515e0d4dc5b9242fa3b7ba806ab9688802431.tar.gz
eclipse.jdt.core-494515e0d4dc5b9242fa3b7ba806ab9688802431.tar.xz
eclipse.jdt.core-494515e0d4dc5b9242fa3b7ba806ab9688802431.zip
Bug 568922 - cannonical constructor for local record throws verify error
Change-Id: Idbbb8aafab293a2588e8e2adb3a015f5078e2ceb Signed-off-by: Manoj Palat <manpalat@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java46
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java3
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java7
3 files changed, 55 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 ee7a55fb30..48567d298a 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
@@ -8014,4 +8014,50 @@ public void testBug561199_001() {
new String[] {"--enable-preview"},
options);
}
+public void testBug568922_001() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " record R() {\n"+
+ " R {\n"+
+ " super();\n"+
+ " System.out.println(\"helo\");\n"+
+ " }\n"+
+ " }\n"+
+ " new R();\n"+
+ " }\n"+
+ "}"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " super();\n" +
+ " ^^^^^^^^\n" +
+ "The body of a compact constructor must not contain an explicit constructor call\n" +
+ "----------\n",
+ null,
+ true,
+ new String[] {"--enable-preview"},
+ getCompilerOptions());
+}
+public void testBug568922_002() {
+ runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n"+
+ " public static void main(String[] args) {\n"+
+ " @SuppressWarnings(\"preview\")\n"+
+ " record R() {\n"+
+ " R {\n"+
+ " System.out.println(\"helo\");\n"+
+ " }\n"+
+ " }\n"+
+ " new R();\n"+
+ " }\n"+
+ "}"
+ },
+ "helo");
+}
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java
index 0c85305629..d5687d032d 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java
@@ -310,7 +310,8 @@ public class ExplicitConstructorCall extends Statement implements Invocation {
if (methodDeclaration == null
|| !methodDeclaration.isConstructor()
|| ((ConstructorDeclaration) methodDeclaration).constructorCall != this) {
- scope.problemReporter().invalidExplicitConstructorCall(this);
+ if (!(methodDeclaration instanceof CompactConstructorDeclaration)) // already flagged for CCD
+ scope.problemReporter().invalidExplicitConstructorCall(this);
// fault-tolerance
if (this.qualification != null) {
this.qualification.resolveType(scope);
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
index ce288dfd2d..867fcf92c8 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java
@@ -82,6 +82,7 @@ import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.RecordComponent;
import org.eclipse.jdt.internal.compiler.ast.ReferenceExpression;
import org.eclipse.jdt.internal.compiler.ast.ReturnStatement;
+import org.eclipse.jdt.internal.compiler.ast.SuperReference;
import org.eclipse.jdt.internal.compiler.ast.SwitchStatement;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
@@ -2446,6 +2447,12 @@ private void checkRecordCanonicalConstructor(MethodBinding explicitCanonicalCons
return true;
}
};
+ if ( methodDecl instanceof CompactConstructorDeclaration) {
+ CompactConstructorDeclaration ccd = (CompactConstructorDeclaration) methodDecl;
+ if (ccd.constructorCall == null) { // local traverse - super not set yet.
+ ccd.constructorCall = SuperReference.implicitSuperConstructorCall();
+ }
+ }
methodDecl.traverse(visitor, this.scope);
}

Back to the top