interp: fix the behaviour of goto, continue and break#1392
Merged
Conversation
The logic of goto was false due to mixing break label and goto label, despite being opposite. In case of break, jump to node (the exit point) instead of node.start. Also always define label symbols before their use is parsed. Fixes traefik#1354.
Collaborator
|
Are you aware that even after this PR, it seems that the behavior of incontinue() is not the same with Go and with Yaegi. |
mpl
reviewed
May 18, 2022
| err = n.cfgErrorf("invalid continue label %s", n.child[0].ident) | ||
| break | ||
| } | ||
| for _, c := range n.sym.from { |
| if n.sym.node == nil { | ||
| break | ||
| } | ||
| for _, c := range n.sym.from { |
Collaborator
There was a problem hiding this comment.
same remark as in break and continue.
| gotoLabel(n.sym) | ||
| for _, c := range n.sym.from { | ||
| if c.kind == gotoStmt { | ||
| c.tnext = n.start |
Collaborator
There was a problem hiding this comment.
If we are not in a forward case, it seems useless to do that, since the code in the goto case (L887) will overwrite c.tnext.
If we are in the forward case, we are overwriting c.tnext here. Is that what we want to do?
mpl
approved these changes
May 18, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The logic of goto was false due to mixing break label and goto
label, despite being opposite. In case of break, jump to node (the
exit point) instead of node.start. Also always define label symbols
before their use is parsed.
Fixes #1354.