[tools] gopls/internal/golang: fix crash in function extraction

0 views
Skip to first unread message

Madeline Kalil (Gerrit)

unread,
12:12 PM (11 hours ago) 12:12 PM
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Hyang-Ah Hana Kim, Go LUCI, Alan Donovan, golang-co...@googlegroups.com

Madeline Kalil submitted the change

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
Reviewed-by: Hyang-Ah Hana Kim <hya...@gmail.com>
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:
  • requirement satisfiedCode-Review: +2 by Hyang-Ah Hana Kim
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I85e33470c98167fe498f925ca2eed2dd59620aa6
Gerrit-Change-Number: 756200
Gerrit-PatchSet: 2
Gerrit-Owner: Madeline Kalil <mka...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Hyang-Ah Hana Kim <hya...@gmail.com>
Gerrit-Reviewer: Madeline Kalil <mka...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages