-
Notifications
You must be signed in to change notification settings - Fork 35
Add #result for Return Refinements
#145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
9d7e2dc
e111574
ab4d600
58a5475
a3bee27
515ddf5
b38a5fc
a0edc1f
4969ce5
98d9760
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package testSuite; | ||
|
|
||
| import liquidjava.specification.Refinement; | ||
|
|
||
| public class CorrectResult { | ||
|
|
||
| @Refinement("$result > 10") | ||
| public int getLargeNumber() { | ||
| return 15; | ||
| } | ||
|
|
||
| @Refinement("$result == (a + b)") | ||
| public int sum(int a, int b) { | ||
| return a + b; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Not Found Error | ||
| package testSuite; | ||
| import liquidjava.specification.Refinement; | ||
|
|
||
| public class ErrorResultVariable { | ||
| public void test() { | ||
| @Refinement("$result > 0") | ||
| int x = 10; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,6 +161,7 @@ private Predicate handleFunctionRefinements(RefinedFunction f, CtElement method, | |
| Optional<Predicate> oret = rtc.getRefinementFromAnnotation(method); | ||
| Predicate ret = oret.orElse(new Predicate()); | ||
| ret = ret.substituteVariable("return", Keys.WILDCARD); | ||
| ret = ret.substituteVariable("$result", Keys.WILDCARD);// added for refinement | ||
|
||
| f.setRefReturn(ret); | ||
| return Predicate.createConjunction(joint, ret); | ||
| } | ||
|
|
@@ -180,6 +181,13 @@ public <R> void getReturnRefinements(CtReturn<R> ret) throws LJError { | |
| RefinedFunction fi = rtc.getContext().getFunction(method.getSimpleName(), | ||
| ((CtClass<?>) method.getParent()).getQualifiedName(), method.getParameters().size()); | ||
|
|
||
| if (fi == null) | ||
| return;// null check refinement | ||
|
|
||
| if (fi.getRefReturn() == null) { | ||
| return; | ||
| } | ||
|
||
|
|
||
| List<Variable> lv = fi.getArguments(); | ||
| for (Variable v : lv) { | ||
| rtc.getContext().addVarToContext(v); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a great idea to change all the IDs to allow the
$. We can improve it by only allowing $result and only in the places it can appear (not when a ghost or state is created for example)