Skip to content

Commit

Permalink
Do not create invalid JavacVariableBinding
Browse files Browse the repository at this point in the history
when underlying VarSymbol is error
  • Loading branch information
mickaelistria committed Jan 8, 2025
1 parent 4628fb2 commit 55121e6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.tree.JCTree.JCWildcard;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.Names;

/**
* Deals with creation of binding model, using the <code>Symbol</code>s from Javac.
Expand Down Expand Up @@ -1221,7 +1222,9 @@ IVariableBinding resolveVariable(VariableDeclaration variable) {
if (this.converter.domToJavac.get(variable) instanceof JCVariableDecl decl) {
// the decl.type can be null when there are syntax errors
if ((decl.type != null && !decl.type.isErroneous()) || this.isRecoveringBindings()) {
return this.bindings.getVariableBinding(decl.sym);
if (decl.name != Names.instance(this.context).error) { // cannot recover if name is error
return this.bindings.getVariableBinding(decl.sym);
}
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
import com.sun.tools.javac.code.Type.WildcardType;
import com.sun.tools.javac.code.Types.FunctionDescriptorLookupError;
import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Names;

public abstract class JavacTypeBinding implements ITypeBinding {

Expand All @@ -100,6 +101,7 @@ public abstract class JavacTypeBinding implements ITypeBinding {
final JavacBindingResolver resolver;
public final TypeSymbol typeSymbol;
private final Types types;
private final Names names;
public final Type type;
private final boolean isGeneric; // only relevent for parameterized types
private boolean recovered = false;
Expand All @@ -115,6 +117,7 @@ public JavacTypeBinding(Type type, final TypeSymbol typeSymbol, boolean isDeclar
this.type = this.isGeneric || type == null ? this.typeSymbol.type /*generic*/ : type /*specific instance*/;
this.resolver = resolver;
this.types = Types.instance(this.resolver.context);
this.names = Names.instance(this.resolver.context);
// TODO: consider getting rid of typeSymbol in constructor and always derive it from type
}

Expand Down Expand Up @@ -552,6 +555,7 @@ public IVariableBinding[] getDeclaredFields() {
return StreamSupport.stream(this.typeSymbol.members().getSymbols().spliterator(), false)
.filter(VarSymbol.class::isInstance)
.map(VarSymbol.class::cast)
.filter(sym -> sym.name != this.names.error)
.map(this.resolver.bindings::getVariableBinding)
.toArray(IVariableBinding[]::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,9 @@ private void processMembers(ITypeBinding typeBinding, Bindings scope,
}

Predicate<IBinding> accessFilter = binding -> {
if (binding == null) {
return false;
}
boolean field = binding instanceof IVariableBinding;
if (field) {
if (impossibleFields.contains(binding.getName())) {
Expand Down

0 comments on commit 55121e6

Please sign in to comment.