Fix returning values through variables as actual parameters #715
+96
−52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When call is made using variable as an actual parameter the variables equality is kept in stack frame bindings to track the value of the variable. At the same time as formal argument variables are local they are not added into the
Stack::vars
set. Thus it is possible that variable equality is wiped when returning from the next nested call. And if after this call value is assigned to the formal argument variable this value will not be assigned to the actual argument variable.In the following example:
calling
(foo $a)
adds variable equality{ $a = $b }
into bindings and$a
is kept insideStack::vars
of the first frame because its value should be passed from the firstchain
's argument to the last one. After executing(chain (function (return ())) $_
bindings are being cleaned up and variable equality is removed from bindings. Thus when$b
receives value it is not propagated to the$a
This fix replaces formal argument variables in a body of a called function by the actual argument value or variable. In the particular case above variable
$b
in(unify $b value (return ()) (return (Error () \"Unexpected error\")) )
is replaced by variable$a
and value is assigned properly.