Change information
Commit message:
gopls/internal/golang: fix crash in function extraction
extractFunctionMethod crashes with "index out of bounds" when it encounters a return statement in a function with no result types. This adds an index check to avoid the crash.
When ill-typed code causes a mismatch between the return type of the extracted block and the return type of its enclosing function, the code that extract generates will still have errors.
However, it still makes more sense to generate an extraction in this case, rather than throw an error and produce nothing - the user can edit the result how they desire.
Fixes golang/go#78142
Change-Id: I85e33470c98167fe498f925ca2eed2dd59620aa6
Files:
- M gopls/internal/golang/extract.go
- A gopls/internal/test/marker/testdata/codeaction/functionextraction_issue78142.txt
Change size: S
Delta: 2 files changed, 40 insertions(+), 5 deletions(-)
Branch: refs/heads/master
Submit Requirements:
Code-Review: +2 by Hyang-Ah Hana Kim
TryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI