Skip to content

Logic for method overload with different types#172

Open
CatarinaGamboa wants to merge 3 commits intomainfrom
overloads
Open

Logic for method overload with different types#172
CatarinaGamboa wants to merge 3 commits intomainfrom
overloads

Conversation

@CatarinaGamboa
Copy link
Collaborator

This PR fixes issue #134 .
We now account for the types of arguments when identifying the function that is called.
The main change is checkInvocationRefinements now has another parameter for the param types, and we change all its calls to capture the arguments' types and call the correct function.

@CatarinaGamboa CatarinaGamboa self-assigned this Mar 10, 2026
@CatarinaGamboa
Copy link
Collaborator Author

@copilot review it

Copy link

Copilot AI commented Mar 10, 2026

@CatarinaGamboa I've opened a new pull request, #173, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes overload resolution for refinement/state transitions by selecting the correct refined function based on parameter types (not just arity), addressing issue #134 in the verifier’s method/constructor invocation checking.

Changes:

  • Add Context.getFunction(name, target, paramTypes) and type-based argument matching for refined function lookup.
  • Thread resolved parameter types through MethodsFunctionsChecker invocation/constructor checking with a safe fallback to arity-based lookup.
  • Add new example test suites covering overloaded constructors (correct and error cases).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/general_checkers/MethodsFunctionsChecker.java Passes resolved parameter types through invocation/constructor refinement selection; adds helper overload for refinement function lookup.
liquidjava-verifier/src/main/java/liquidjava/processor/context/Context.java Adds type-based refined function lookup via parameter type matching.
liquidjava-example/src/main/java/testSuite/classes/overload_constructors_error/ThrowableRefinements.java Adds external refinements for Throwable to reproduce the overloaded-constructor state transition bug.
liquidjava-example/src/main/java/testSuite/classes/overload_constructors_error/Test.java Adds failing example where the Throwable(Throwable) constructor should prevent initCause.
liquidjava-example/src/main/java/testSuite/classes/overload_constructors_error/.expected Declares expected failure title for the error suite.
liquidjava-example/src/main/java/testSuite/classes/overload_constructors_correct/ThrowableRefinements.java Same refinements used for the passing variant of the scenario.
liquidjava-example/src/main/java/testSuite/classes/overload_constructors_correct/Test.java Adds passing example where initCause is not invoked after Throwable(Throwable).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

CatarinaGamboa and others added 2 commits March 9, 2026 22:41
…nstructors_error/ThrowableRefinements.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…nstructors_error/Test.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
&& argumentTypesMatch(fi.getArguments(), paramTypes))
return fi;
}
return null;
Copy link
Collaborator

@rcosta358 rcosta358 Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a fallback everywhere this method is called, where if the lookup by exact parameter types returns null we try to get the function by the number of parameters, we could just call it here:

Suggested change
return null;
return getFunction(name, target, paramTypes.size());

I tested it locally and it worked fine.

Comment on lines +67 to +69
if (f == null)
f = rtc.getContext().getFunction(exe.getSimpleName(), exe.getDeclaringType().getQualifiedName(),
ctConstructorCall.getArguments().size());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (f == null)
f = rtc.getContext().getFunction(exe.getSimpleName(), exe.getDeclaringType().getQualifiedName(),
ctConstructorCall.getArguments().size());

Comment on lines +230 to +231
if (f == null)
f = rtc.getContext().getFunction(method.getSimpleName(), ctype, invocation.getArguments().size());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (f == null)
f = rtc.getContext().getFunction(method.getSimpleName(), ctype, invocation.getArguments().size());

Comment on lines +249 to +252
if (f == null)
f = rtc.getContext().getFunction(String.format("%s.%s", className, methodName), className, paramTypes);
if (f == null)
f = getRefinementFunction(methodName, className, paramTypes.size());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (f == null)
f = rtc.getContext().getFunction(String.format("%s.%s", className, methodName), className, paramTypes);
if (f == null)
f = getRefinementFunction(methodName, className, paramTypes.size());

Comment on lines +272 to +273
if (f == null)
f = rtc.getContext().getFunction(qualifiedSignature, ctype, argSize);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (f == null)
f = rtc.getContext().getFunction(qualifiedSignature, ctype, argSize);

Comment on lines +282 to +283
if (f == null)
f = rtc.getContext().getFunction(signature, ctype, argSize);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (f == null)
f = rtc.getContext().getFunction(signature, ctype, argSize);

Comment on lines +290 to +291
if (f == null)
f = rtc.getContext().getFunction(name, ctype, argSize);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (f == null)
f = rtc.getContext().getFunction(name, ctype, argSize);

Comment on lines +300 to +301
if (f == null)
f = rtc.getContext().getFunction(completeName, ctype, argSize);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (f == null)
f = rtc.getContext().getFunction(completeName, ctype, argSize);

Comment on lines +321 to +322
if (f == null)
f = rtc.getContext().getFunction(methodName, className, arguments.size());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (f == null)
f = rtc.getContext().getFunction(methodName, className, arguments.size());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants