Skip to content

Commit 1ac3ef7

Browse files
Fix Refined Method Overloading
Co-Authored-By: Márcio Caetano <153174341+rodrigomilisse@users.noreply.github.com>
1 parent 368df95 commit 1ac3ef7

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package testSuite.classes.method_overload_correct;
2+
3+
import liquidjava.specification.ExternalRefinementsFor;
4+
import liquidjava.specification.Refinement;
5+
6+
@ExternalRefinementsFor("java.util.concurrent.Semaphore")
7+
public interface DummySemaphoreRefinements {
8+
9+
public abstract void acquire();
10+
11+
public abstract void acquire(@Refinement("_ >= 0") int permits) throws InterruptedException;
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package testSuite.classes.method_overload_correct;
2+
3+
import java.util.concurrent.Semaphore;
4+
5+
public class TestMethodOverloadCorrect {
6+
public static void main(String[] args) throws InterruptedException {
7+
Semaphore sem = new Semaphore(1);
8+
sem.acquire(1);
9+
}
10+
}

liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/general_checkers/MethodsFunctionsChecker.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public <R> void getReturnRefinements(CtReturn<R> ret) {
191191
return;
192192
if (method.getParent() instanceof CtClass) {
193193
RefinedFunction fi = rtc.getContext().getFunction(method.getSimpleName(),
194-
((CtClass<?>) method.getParent()).getQualifiedName());
194+
((CtClass<?>) method.getParent()).getQualifiedName(), method.getParameters().size());
195195

196196
List<Variable> lv = fi.getArguments();
197197
for (Variable v : lv) {
@@ -229,7 +229,8 @@ public <R> void getInvocationRefinements(CtInvocation<R> invocation) {
229229

230230
} else if (method.getParent() instanceof CtClass) {
231231
String ctype = ((CtClass<?>) method.getParent()).getQualifiedName();
232-
RefinedFunction f = rtc.getContext().getFunction(method.getSimpleName(), ctype);
232+
int argSize = invocation.getArguments().size();
233+
RefinedFunction f = rtc.getContext().getFunction(method.getSimpleName(), ctype, argSize);
233234
if (f != null) { // inside rtc.context
234235
checkInvocationRefinements(invocation, invocation.getArguments(), invocation.getTarget(),
235236
method.getSimpleName(), ctype);
@@ -264,13 +265,14 @@ private void searchMethodInLibrary(CtExecutableReference<?> ctr, CtInvocation<?>
264265
String ctype = (ctref != null) ? ctref.toString() : null;
265266

266267
String name = ctr.getSimpleName(); // missing
267-
if (rtc.getContext().getFunction(name, ctype) != null) { // inside rtc.context
268+
int argSize = invocation.getArguments().size();
269+
if (rtc.getContext().getFunction(name, ctype, argSize) != null) { // inside rtc.context
268270
checkInvocationRefinements(invocation, invocation.getArguments(), invocation.getTarget(), name, ctype);
269271
return;
270272
} else {
271273
String prefix = ctype;
272274
String completeName = String.format("%s.%s", prefix, name);
273-
if (rtc.getContext().getFunction(completeName, ctype) != null) {
275+
if (rtc.getContext().getFunction(completeName, ctype, argSize) != null) {
274276
checkInvocationRefinements(invocation, invocation.getArguments(), invocation.getTarget(), completeName,
275277
ctype);
276278
}

liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/general_checkers/OperationsChecker.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ private Predicate getOperationRefinements(CtBinaryOperator<?> operator, CtVariab
249249

250250
// Get function refinements with non_used variables
251251
String met = ((CtClass<?>) method.getParent()).getQualifiedName(); // TODO check
252-
RefinedFunction fi = rtc.getContext().getFunction(method.getSimpleName(), met);
252+
RefinedFunction fi = rtc.getContext().getFunction(method.getSimpleName(), met, inv.getArguments().size());
253253
Predicate innerRefs = fi.getRenamedRefinements(rtc.getContext(), inv); // TODO REVER!!
254254
// Substitute _ by the variable that we send
255255
String newName = String.format(rtc.freshFormat, rtc.getContext().getCounter());
@@ -275,7 +275,8 @@ private Predicate getOperationRefinementFromExternalLib(CtInvocation<?> inv, CtB
275275
int i = c.indexOf("<");
276276
String typeNotParametrized = (i > 0) ? c.substring(0, i) : c;
277277
String methodInClassName = typeNotParametrized + "." + simpleName;
278-
RefinedFunction fi = rtc.getContext().getFunction(methodInClassName, typeNotParametrized);
278+
RefinedFunction fi = rtc.getContext().getFunction(methodInClassName, typeNotParametrized,
279+
inv.getArguments().size());
279280
Predicate innerRefs = fi.getRenamedRefinements(rtc.getContext(), inv); // TODO REVER!!
280281

281282
// Substitute _ by the variable that we send

0 commit comments

Comments
 (0)