Skip to content
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

interp: correctly init variables assigned from function call #1529

Merged
merged 5 commits into from
Mar 24, 2023

Conversation

mvertes
Copy link
Member

@mvertes mvertes commented Mar 22, 2023

In the case of a Go short definition (i.e. a, b := f()), the new defined variables must be (re-)created in order to preserve the previous value (if in a loop) which can be still in use in the context of a closure. This must not apply to redeclared variables which simply see their value reassigned.

The problem was both occuring in callBin() for runtime functions and assignFromCall() for functions created in the interpreter.

Fixes #1497.

In the case of a Go short definition (i.e. `a, b := f()`), the
new defined variables must be (re-)created in order to preserve the
previous value (if in a loop) which can be still in use in the
context of a closure. This must not apply to redeclared variables
which simply see their value reassigned.

The problem was both occuring in callBin() for runtime functions
and assignFromCall() for functions created in the interpreter.

Fixes traefik#1497.
@mvertes mvertes added this to the v0.15.x milestone Mar 22, 2023
@mvertes mvertes requested a review from mpl March 22, 2023 10:01
_test/closure13.go Outdated Show resolved Hide resolved
Co-authored-by: mpl <mathieu.lonjaret@gmail.com>
interp/run.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@mpl mpl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after last typo fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

double assignment + closure, in a for loop, reuses the same variable, instead of assigning to a new one.
3 participants