Shortcut equivalence check if ctdecl is unresolved

This commit is contained in:
Clément Fournier committed 2023-01-25 12:09:08 +01:00
1 parent 8ef6042eb4
commit 869752bc34
2 files changed
+5 -10

No files matched your search

@@ -133,16 +133,8 @@ public class UseDiamondOperatorRule extends AbstractJavaRulechainRule {
MethodCallSite fakeCallSite = infer.newCallSite(mirror, targetType);
infer.inferInvocationRecursively(fakeCallSite);
try {
return mirror.isEquivalentToUnderlyingAst()
&& topmostContext.acceptsType(mirror.getInferredType());
} catch (IllegalStateException e) {
/*
* overload resolution may complaint it's incomplete if there are missing types.
* The missing type info may be relevant to the user, but this exception is not, swallow it
*/
return false;
}
return mirror.isEquivalentToUnderlyingAst()
&& topmostContext.acceptsType(mirror.getInferredType());
}
@@ -40,6 +40,9 @@ abstract class BaseInvocMirror<T extends InvocationNode> extends BasePolyMirror<
public boolean isEquivalentToUnderlyingAst() {
MethodCtDecl ctDecl = getCtDecl();
AssertionUtil.validateState(ctDecl != null, "overload resolution is not complete");
if (ctDecl.isFailed()) {
return false; // be conservative
}
if (!myNode.getMethodType().getSymbol().equals(ctDecl.getMethodType().getSymbol())) {
return false;
} else if (myNode instanceof ASTConstructorCall && ((ASTConstructorCall) myNode).isAnonymousClass()