Logic for method overload with different types#172
Logic for method overload with different types#172CatarinaGamboa wants to merge 3 commits intomainfrom
Conversation
|
@copilot review it |
|
@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. |
There was a problem hiding this comment.
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
MethodsFunctionsCheckerinvocation/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.
...xample/src/main/java/testSuite/classes/overload_constructors_error/ThrowableRefinements.java
Outdated
Show resolved
Hide resolved
liquidjava-example/src/main/java/testSuite/classes/overload_constructors_error/Test.java
Outdated
Show resolved
Hide resolved
…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; |
There was a problem hiding this comment.
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:
| return null; | |
| return getFunction(name, target, paramTypes.size()); |
I tested it locally and it worked fine.
| if (f == null) | ||
| f = rtc.getContext().getFunction(exe.getSimpleName(), exe.getDeclaringType().getQualifiedName(), | ||
| ctConstructorCall.getArguments().size()); |
There was a problem hiding this comment.
| if (f == null) | |
| f = rtc.getContext().getFunction(exe.getSimpleName(), exe.getDeclaringType().getQualifiedName(), | |
| ctConstructorCall.getArguments().size()); |
| if (f == null) | ||
| f = rtc.getContext().getFunction(method.getSimpleName(), ctype, invocation.getArguments().size()); |
There was a problem hiding this comment.
| if (f == null) | |
| f = rtc.getContext().getFunction(method.getSimpleName(), ctype, invocation.getArguments().size()); |
| if (f == null) | ||
| f = rtc.getContext().getFunction(String.format("%s.%s", className, methodName), className, paramTypes); | ||
| if (f == null) | ||
| f = getRefinementFunction(methodName, className, paramTypes.size()); |
There was a problem hiding this comment.
| if (f == null) | |
| f = rtc.getContext().getFunction(String.format("%s.%s", className, methodName), className, paramTypes); | |
| if (f == null) | |
| f = getRefinementFunction(methodName, className, paramTypes.size()); |
| if (f == null) | ||
| f = rtc.getContext().getFunction(qualifiedSignature, ctype, argSize); |
There was a problem hiding this comment.
| if (f == null) | |
| f = rtc.getContext().getFunction(qualifiedSignature, ctype, argSize); |
| if (f == null) | ||
| f = rtc.getContext().getFunction(signature, ctype, argSize); |
There was a problem hiding this comment.
| if (f == null) | |
| f = rtc.getContext().getFunction(signature, ctype, argSize); |
| if (f == null) | ||
| f = rtc.getContext().getFunction(name, ctype, argSize); |
There was a problem hiding this comment.
| if (f == null) | |
| f = rtc.getContext().getFunction(name, ctype, argSize); |
| if (f == null) | ||
| f = rtc.getContext().getFunction(completeName, ctype, argSize); |
There was a problem hiding this comment.
| if (f == null) | |
| f = rtc.getContext().getFunction(completeName, ctype, argSize); |
| if (f == null) | ||
| f = rtc.getContext().getFunction(methodName, className, arguments.size()); |
There was a problem hiding this comment.
| if (f == null) | |
| f = rtc.getContext().getFunction(methodName, className, arguments.size()); |
This PR fixes issue #134 .
We now account for the types of arguments when identifying the function that is called.
The main change is
checkInvocationRefinementsnow has another parameter for the param types, and we change all its calls to capture the arguments' types and call the correct function.