Skip to content

Commit dbaa212

Browse files
Name refined call results after the method, as the other generated values
The result of a call to a method with a contract was named #<method>_N and shown as getUndoManager⁵⁵⁵, like a program variable. It is now a generated name, #getUndoManager_result⁵⁵⁵, as the results of the calls inside an expression already were. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent cd49fea commit dbaa212

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import liquidjava.processor.refinement_checker.object_checkers.AuxHierarchyRefinementsPassage;
1717
import liquidjava.processor.refinement_checker.object_checkers.AuxStateHandler;
1818
import liquidjava.rj_language.Predicate;
19+
import liquidjava.utils.GeneratedNames;
1920
import liquidjava.utils.Utils;
2021
import liquidjava.utils.constants.Formats;
2122
import liquidjava.utils.constants.Keys;
@@ -330,7 +331,7 @@ private boolean tryRefinements(CtInvocation<?> invocation, String key, String ct
330331
return true;
331332
}
332333

333-
private Map<String, String> checkInvocationRefinements(CtElement invocation, List<CtExpression<?>> arguments,
334+
private Map<String, String> checkInvocationRefinements(CtExpression<?> invocation, List<CtExpression<?>> arguments,
334335
CtExpression<?> target, String methodName, String className, List<CtTypeReference<?>> paramTypes)
335336
throws LJError {
336337
// -- Part 1: Check if the invocation is possible
@@ -373,11 +374,11 @@ private Map<String, String> checkInvocationRefinements(CtElement invocation, Lis
373374
* matches the post-call VariableInstance. Returns {@code null} for void methods. When the function has no
374375
* refinements to check, the (empty) instance is registered eagerly.
375376
*/
376-
private String prepareReturnInstance(CtElement invocation, RefinedFunction f) {
377+
private String prepareReturnInstance(CtExpression<?> invocation, RefinedFunction f) {
377378
CtTypeReference<?> retType = f.getType();
378379
if (retType == null || "void".equals(retType.toString()))
379380
return null;
380-
String returnViName = String.format(Formats.INSTANCE, f.getName(), rtc.getContext().getCounter());
381+
String returnViName = GeneratedNames.valueOf(invocation, rtc.getContext().getCounter());
381382
invocation.putMetadata(Keys.RETURN_VAR_NAME, returnViName);
382383
if (f.allRefinementsTrue())
383384
rtc.getContext().addInstanceToContext(returnViName, retType, new Predicate(), invocation);
@@ -388,7 +389,7 @@ private String prepareReturnInstance(CtElement invocation, RefinedFunction f) {
388389
* Part 2 of an invocation check: applies the function's return refinement to the context, substituting argument and
389390
* target variables and registering the resulting return-value instance.
390391
*/
391-
private void applyReturnRefinement(CtElement invocation, RefinedFunction f, Map<String, String> map,
392+
private void applyReturnRefinement(CtExpression<?> invocation, RefinedFunction f, Map<String, String> map,
392393
String returnViName) {
393394
Predicate methodRef = f.getRefReturn();
394395
if (methodRef == null)
@@ -410,7 +411,7 @@ private void applyReturnRefinement(CtElement invocation, RefinedFunction f, Map<
410411
}
411412

412413
String viName = returnViName != null ? returnViName
413-
: String.format(Formats.INSTANCE, f.getName(), rtc.getContext().getCounter());
414+
: GeneratedNames.valueOf(invocation, rtc.getContext().getCounter());
414415
VariableInstance vi = (VariableInstance) rtc.getContext().addInstanceToContext(viName, f.getType(),
415416
methodRef.substituteVariable(Keys.WILDCARD, viName), invocation); // TODO REVIEW!!
416417
if (varName != null && f.hasStateChange() && equalsThis)

‎liquidjava-verifier/src/test/java/liquidjava/api/tests/TestGeneratedNames.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ void namesEachGeneratedValueAfterWhatItIs() {
2222
Map<Integer, String> messages = Diagnostics.getInstance().getErrors().stream().collect(Collectors.toMap(
2323
error -> error.getPosition().getLine(), error -> error.getMessage().replaceAll("[⁰¹²³⁴⁵⁶⁷⁸⁹]", "")));
2424

25-
assertEquals(Map.of(25, "#if_condition == ready && #if_condition is not a subtype of a > 0", 30,
26-
"#loop_condition == ready && #loop_condition == true is not a subtype of a > 0", 34,
27-
"#ternary_condition == ready && #ternary_condition == true is not a subtype of a < 0", 43,
25+
assertEquals(Map.of(25, "#if_condition == #ready_result && #if_condition is not a subtype of a > 0", 30,
26+
"#loop_condition == #ready_result && #loop_condition == true is not a subtype of a > 0", 34,
27+
"#ternary_condition == #ready_result && #ternary_condition == true is not a subtype of a < 0", 43,
2828
"!#try_branch && !#catch_branch is not a subtype of a > 0", 48,
2929
"x == #read_result - 1 is not a subtype of x > 0", 54,
3030
"#if_condition == #operation_result && #if_condition && x == 0 is not a subtype of x > 0", 58,

0 commit comments

Comments
 (0)