Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
LoiNguyenCS committed Nov 29, 2023
1 parent fac4435 commit 3ec9735
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,11 @@ public Visitable visit(MethodCallExpr call, Void p) {
if (call.getScope().isPresent()) {
// the scope of a method will always be a NameExpr, while that NameExpr might be a field,
// variable, or a class.
NameExpr expression = call.getScope().get().asNameExpr();
updateUsedElementWithPotentialFieldNameExpr(expression);
Expression scope = call.getScope().get();
if (scope instanceof NameExpr) {
NameExpr expression = call.getScope().get().asNameExpr();
updateUsedElementWithPotentialFieldNameExpr(expression);
}
}
}
return super.visit(call, p);
Expand Down Expand Up @@ -351,7 +354,13 @@ private void resolveUnionType(UnionType type) {
* @param expr a field access expression inside target methods
*/
public void updateUsedElementWithPotentialFieldNameExpr(NameExpr expr) {
ResolvedValueDeclaration exprDecl = expr.resolve();
ResolvedValueDeclaration exprDecl;
try {
exprDecl = expr.resolve();
} catch (UnsolvedSymbolException e) {
// if expr is the name of a class in a static call, we can't resolve its value.
return;
}
if (exprDecl instanceof ResolvedFieldDeclaration) {
// while the name of the method is declaringType(), it actually returns the class where the
// field is declared
Expand Down

0 comments on commit 3ec9735

Please sign in to comment.