Skip to content

Commit

Permalink
Added TypeBinding for Array-Declared Fields
Browse files Browse the repository at this point in the history
  • Loading branch information
subyssurendran666 committed Feb 13, 2025
1 parent 668fa97 commit 8f9d78f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -563,4 +563,40 @@ public enum LoginType {

assertNotNull("ASTNode creation failed. Node is null!", node);
}

public void testBug3734() throws CoreException {
ASTParser astParser = ASTParser.newParser(getAST23());
Map<String, String> options = new HashMap<>();
options.put(JavaCore.COMPILER_COMPLIANCE, "23");
options.put(JavaCore.COMPILER_SOURCE, "23");

astParser.setCompilerOptions(options);
astParser.setEnvironment(new String[] {}, new String[] {}, new String[] {}, true);
astParser.setUnitName("X.java");
astParser.setResolveBindings(true);
astParser.setBindingsRecovery(true);

String source ="""
public class X {
int[] x = new int[1];
int[] y = new int[1];
int test(int a) {
this.y[0] = a;
return this.x[0] = a;
}
}
""";

astParser.setSource(source.toCharArray());

CompilationUnit compilationUnit = (CompilationUnit) astParser.createAST(null);
TypeDeclaration a = (TypeDeclaration) compilationUnit.types().get(0);

ITypeBinding aBinding = a.resolveBinding();
IVariableBinding[] fieldBinding = aBinding.getDeclaredFields();

assertEquals("Mismatch in field",fieldBinding.length, 2);


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ private synchronized ITypeBinding internalGetTypeBinding(org.eclipse.jdt.interna
}
ITypeBinding binding = (ITypeBinding) this.bindingTables.compilerBindingsToASTBindings.get(referenceBinding);
if (binding != null) {
if (referenceBinding.fields() != null && referenceBinding.fields().length > 0)
binding.getDeclaredFields();
return binding;
}
binding = TypeBinding.createTypeBinding(this, referenceBinding, declaringMember);
Expand Down

0 comments on commit 8f9d78f

Please sign in to comment.