Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2021-10-15 09:12:58 +0000
committerManoj Palat2021-10-18 08:30:29 +0000
commit0171fc1ad417c06219cf50676a497f9d6bf85749 (patch)
tree587825fabafdf4ca7e668c43aeccac27a6a6e223
parent0922db59e4c58ea2a2856dccfd45d2a7c723deef (diff)
downloadeclipse.jdt.core-0171fc1ad417c06219cf50676a497f9d6bf85749.tar.gz
eclipse.jdt.core-0171fc1ad417c06219cf50676a497f9d6bf85749.tar.xz
eclipse.jdt.core-0171fc1ad417c06219cf50676a497f9d6bf85749.zip
Bug 576448 - Compile error shown when working with records though
everything runs fine Change-Id: I6861c6ebab950fe696a9b766cd176809d1ca2bd8 Signed-off-by: Manoj Palat <manpalat@in.ibm.com> Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/186521 Tested-by: JDT Bot <jdt-bot@eclipse.org>
-rw-r--r--org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests16.java58
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ExtendedTagBits.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java15
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java5
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java11
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java4
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java4
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodBinding.java2
11 files changed, 92 insertions, 18 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests16.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests16.java
index bdc8992828..1eb2eceabd 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests16.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ReconcilerTests16.java
@@ -193,4 +193,62 @@ public void _testBug570399_002() throws Exception {
deleteProject(p);
}
}
+public void testBug576448_001() throws Exception {
+ if (!isJRE16)
+ return;
+ IJavaProject p = createJava16Project("p");
+ createFolder("/p/src/a");
+ try {
+ createFile("p/src/a/X.java",
+ "package a;\n"+
+ "import a.Interface.NestedInterface;\n"+
+ "import a.Interface.NestedInterface2;\n"+
+ "\n"+
+ "public record X(String someString, NestedInterface someInterface) implements NestedInterface2 {\n"+
+ " public X(NestedInterface someInterface) {\n"+
+ " this(null, someInterface); // <- error here\n"+
+ " }\n"+
+ " public X(String someString, NestedInterface someInterface) {\n"+
+ " this.someString = someString;\n"+
+ " this.someInterface = someInterface;\n"+
+ " }\n"+
+ " public static void main(String[] args) {\n"+
+ " System.out.println(\"hello\");\n"+
+ " }\n"+
+ "}");
+ createFile("p/src/a/Interface.java",
+ "package a;\n"+
+ "public interface Interface {\n"+
+ " interface NestedInterface {\n"+
+ " }\n"+
+ " interface NestedInterface2 {\n"+
+ " String someString();\n"+
+ " NestedInterface someInterface();\n"+
+ " static NestedInterface2 create(String s, NestedInterface n) {\n"+
+ " return new X(s, n);\n"+
+ " }\n"+
+ " static NestedInterface2 create(NestedInterface n) {\n"+
+ " return new X(n);\n"+
+ " }\n"+
+ " }\n"+
+ "}");
+
+ p.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
+ IMarker[] markers = p.getProject().findMarkers(null, true, IResource.DEPTH_INFINITE);
+ assertMarkers("markers in p",
+ "",
+ markers);
+
+ this.workingCopy = getCompilationUnit("p/src/X.java").getWorkingCopy(this.wcOwner, null);
+ this.problemRequestor.initialize(this.workingCopy.getSource().toCharArray());
+ this.workingCopy.reconcile(JLS_LATEST, true, this.wcOwner, null);
+ assertProblems("Expecting no problems",
+ "----------\n" +
+ "----------\n",
+ this.problemRequestor);
+ this.workingCopy.discardWorkingCopy();
+ } finally {
+ deleteProject(p);
+ }
+}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
index e03607f2f0..218bc9f71b 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java
@@ -658,7 +658,7 @@ public void resolveStatements() {
this.constructorCall = null;
} else if (sourceType.isRecord() &&
!(this instanceof CompactConstructorDeclaration) && // compact constr should be marked as canonical?
- (this.binding != null && (this.binding.tagBits & TagBits.IsCanonicalConstructor) == 0) &&
+ (this.binding != null && !this.binding.isCanonicalConstructor()) &&
this.constructorCall.accessMode != ExplicitConstructorCall.This) {
this.scope.problemReporter().recordMissingExplicitConstructorCallInNonCanonicalConstructor(this);
this.constructorCall = null;
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 6f4f5c6d39..37bac3808f 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
@@ -308,7 +308,7 @@ public class ExplicitConstructorCall extends Statement implements Invocation {
try {
AbstractMethodDeclaration methodDeclaration = methodScope.referenceMethod();
if (methodDeclaration != null && methodDeclaration.binding != null
- && (methodDeclaration.binding.tagBits & TagBits.IsCanonicalConstructor) != 0) {
+ && methodDeclaration.binding.isCanonicalConstructor()) {
if (!checkAndFlagExplicitConstructorCallInCanonicalConstructor(methodDeclaration, scope))
return;
}
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 c9233c5586..34c9a2476f 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
@@ -482,7 +482,7 @@ public class ClassScope extends Scope {
hasAbstractMethods = hasAbstractMethods || methodBinding.isAbstract();
hasNativeMethods = hasNativeMethods || methodBinding.isNative();
if (methods[i].isCanonicalConstructor()) {
- methodBinding.tagBits |= TagBits.IsCanonicalConstructor;
+ methodBinding.extendedTagBits |= ExtendedTagBits.IsCanonicalConstructor;
}
}
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ExtendedTagBits.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ExtendedTagBits.java
index 0e96a532b5..6d87856bbe 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ExtendedTagBits.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ExtendedTagBits.java
@@ -24,4 +24,9 @@ public interface ExtendedTagBits {
* Flag used to identify the annotation jdk.internal.ValueBased
*/
int AnnotationValueBased = ASTNode.Bit3;
+
+ // Java 16 Records
+ int IsCanonicalConstructor = ASTNode.Bit4; // constructor
+ int isImplicit = ASTNode.Bit5; // constructor and method
+
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java
index eca6e42792..239d1f4a26 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java
@@ -65,6 +65,7 @@ public class MethodBinding extends Binding {
public TypeVariableBinding[] typeVariables = Binding.NO_TYPE_VARIABLES;
char[] signature;
public long tagBits;
+ public int extendedTagBits = 0; // See values in the interface ExtendedTagBits
// Used only for constructors
protected AnnotationBinding [] typeAnnotations = Binding.NO_ANNOTATIONS;
@@ -803,6 +804,12 @@ public final boolean isConstructor() {
return this.selector == TypeConstants.INIT;
}
+/* Answer true if the method is a canonical constructor
+*/
+public final boolean isCanonicalConstructor() {
+ return (this.extendedTagBits & ExtendedTagBits.IsCanonicalConstructor) != 0;
+}
+
/* Answer true if the receiver is a compact constructor
*/
public final boolean isCompactConstructor() {
@@ -846,6 +853,14 @@ public final boolean isImplementing() {
return (this.modifiers & ExtraCompilerModifiers.AccImplementing) != 0;
}
+
+/* Answer true if the method is an implicit method - only for records
+*/
+public final boolean isImplicit() {
+ return (this.extendedTagBits & ExtendedTagBits.isImplicit) != 0;
+}
+
+
/*
* Answer true if the receiver is a "public static void main(String[])" method
*/
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java
index ac5af5d17d..645aabd81c 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java
@@ -449,8 +449,9 @@ MethodBinding createMethod(AbstractMethodDeclaration method) {
}
private void checkAndSetRecordCanonicalConsAndMethods(AbstractMethodDeclaration am) {
if (am.binding != null && (am.bits & ASTNode.IsImplicit) != 0) {
- am.binding.tagBits |= TagBits.isImplicit;
- am.binding.tagBits |= (am.bits & ASTNode.IsCanonicalConstructor) != 0 ? TagBits.IsCanonicalConstructor : 0;
+ am.binding.extendedTagBits |= ExtendedTagBits.isImplicit;
+ if ((am.bits & ASTNode.IsCanonicalConstructor) != 0)
+ am.binding.extendedTagBits |= ExtendedTagBits.IsCanonicalConstructor;
}
}
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 26f9a75611..f5b5644a0a 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
@@ -881,8 +881,7 @@ public List<MethodBinding> checkAndAddSyntheticRecordOverrideMethods(MethodBindi
if (this.isRecordDeclaration && getImplicitCanonicalConstructor() == -1) {
MethodBinding explicitCanon = null;
for (MethodBinding m : methodBindings) {
- if (m.isCompactConstructor()
- || (m.tagBits & TagBits.IsCanonicalConstructor) != 0) {
+ if (m.isCompactConstructor() || m.isCanonicalConstructor()) {
explicitCanon = m;
break;
}
@@ -2184,7 +2183,7 @@ private int getImplicitCanonicalConstructor() {
if (this.methods != null && this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK14) {
for (int i = 0, l = this.methods.length; i < l; ++i) {
MethodBinding method = this.methods[i];
- if ((method.tagBits & TagBits.IsCanonicalConstructor ) != 0 && (method.tagBits & TagBits.isImplicit) != 0)
+ if (method.isCanonicalConstructor() && method.isImplicit())
return i;
}
}
@@ -2197,7 +2196,7 @@ private MethodBinding checkAndGetExplicitCanonicalConstructors() {
for (MethodBinding method : this.methods) {
if (!method.isConstructor())
continue;
- if ((method.tagBits & TagBits.isImplicit) != 0) {
+ if (method.isImplicit()) {
continue;
}
if (method.parameters.length != nRecordComponents)
@@ -2226,7 +2225,7 @@ private int getImplicitMethod(MethodBinding[] resolvedMethods, char[] name) {
MethodBinding method = resolvedMethods[i];
if (method == null || !CharOperation.equals(method.selector, name))
continue;
- if ((method.tagBits & TagBits.isImplicit) != 0 || method instanceof SyntheticMethodBinding)
+ if (method.isImplicit() || method instanceof SyntheticMethodBinding)
return i;
}
}
@@ -2548,7 +2547,7 @@ private MethodBinding checkRecordCanonicalConstructor(MethodBinding explicitCano
if (explicitCanonicalConstructor.thrownExceptions != null && explicitCanonicalConstructor.thrownExceptions.length > 0)
this.scope.problemReporter().recordCanonicalConstructorHasThrowsClause(methodDecl);
checkCanonicalConstructorParameterNames(explicitCanonicalConstructor, methodDecl);
- explicitCanonicalConstructor.tagBits |= TagBits.IsCanonicalConstructor;
+ explicitCanonicalConstructor.extendedTagBits |= ExtendedTagBits.IsCanonicalConstructor;
// checkAndFlagExplicitConstructorCallInCanonicalConstructor(methodDecl);
return explicitCanonicalConstructor;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java
index ad2dfe5bbd..7214a75fc9 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SyntheticMethodBinding.java
@@ -440,7 +440,8 @@ public class SyntheticMethodBinding extends MethodBinding {
if (this.declaringClass.isStrictfp())
this.modifiers |= ClassFileConstants.AccStrictfp;
this.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
- this.tagBits |= (TagBits.IsCanonicalConstructor | TagBits.isImplicit);
+ this.extendedTagBits |= ExtendedTagBits.IsCanonicalConstructor;
+ this.extendedTagBits |= ExtendedTagBits.isImplicit;
this.parameters = rcb.length == 0 ? Binding.NO_PARAMETERS : new TypeBinding[rcb.length];
for (int i = 0; i < rcb.length; i++) this.parameters[i] = TypeBinding.VOID; // placeholder
this.selector = TypeConstants.INIT;
@@ -448,7 +449,6 @@ public class SyntheticMethodBinding extends MethodBinding {
this.purpose = SyntheticMethodBinding.RecordCanonicalConstructor;
this.thrownExceptions = Binding.NO_EXCEPTIONS;
this.declaringClass = declaringSourceType;
- this.tagBits |= TagBits.IsCanonicalConstructor;
this.index = nextSmbIndex();
}
public SyntheticMethodBinding(ReferenceBinding declaringClass, RecordComponentBinding rcb, int index) {
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java
index 26262bfcb2..e21b039837 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java
@@ -65,10 +65,6 @@ public interface TagBits {
long MultiCatchParameter = ASTNode.Bit13; // local
long IsResource = ASTNode.Bit14; // local
- // for java 14 Records Canonical constructor (preview)
- long IsCanonicalConstructor = ASTNode.Bit12; // constructor
- long isImplicit = ASTNode.Bit13; // constructor and method
-
// have implicit null annotations been collected (inherited(?) & default)?
long IsNullnessKnown = ASTNode.Bit13; // method
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodBinding.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodBinding.java
index 2d892d0be7..fbccd7aca4 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodBinding.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodBinding.java
@@ -86,7 +86,7 @@ class MethodBinding implements IMethodBinding {
*/
@Override
public boolean isCanonicalConstructor() {
- return ((this.binding.tagBits & TagBits.IsCanonicalConstructor) != 0);
+ return this.binding.isCanonicalConstructor();
}
/**

Back to the top