Skip to content

interp: correctly init variables assigned from function call#1529

Merged
traefiker merged 5 commits into
traefik:masterfrom
mvertes:fix-1497
Mar 24, 2023
Merged

interp: correctly init variables assigned from function call#1529
traefiker merged 5 commits into
traefik:masterfrom
mvertes:fix-1497

Conversation

@mvertes

@mvertes mvertes commented Mar 22, 2023

Copy link
Copy Markdown
Collaborator

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
Comment thread _test/closure13.go Outdated
Comment thread interp/run.go Outdated

@mpl mpl left a comment

Copy link
Copy Markdown
Collaborator

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