fix(cmd): Handle imbalanced LHS and RHS in defer assignment #100
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.
In #96, @DavidArchibald reported (and provided a fix for)
a bug where the following would cause a panic:
The panic was:
And the panic was caused by the following code:
The reason for the panic is that the LHS and RHS are imbalanced.
The LHS contains two identifiers, but RHS contains only one expression.
So
assign.Rhs[i]
panics wheni
is 1.The fix provided in #96 was more complex than is necessary for this case.
This commit proposes a simpler fix:
We already handle this kind of multi-return function
when it's part of a
return
statement by usingWrapN
functions.We can use the same logic to handle the case where the multi-return
function is part of an assignment in the defer statement.
As with handling of return statements,
this only supports cases where the error is the last return value.
The following will be skipped:
Test case borrowed from #96 and modified to represent the new behavior.