-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gopls/internal/golang: fix bad slice append in function extraction
With multiple return statements, a slice append would overwrite the return values of earlier returns. Fix by using slices.Concat. For golang/go#66289 Change-Id: Ib23bcb9ff297aa1ce9511c7ae54e692b14facca7 Reviewed-on: https://go-review.googlesource.com/c/tools/+/627537 Reviewed-by: Hongxiang Jiang <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
- Loading branch information
Showing
3 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
52 changes: 52 additions & 0 deletions
52
gopls/internal/test/marker/testdata/codeaction/functionextraction_issue66289.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
-- a.go -- | ||
package a | ||
|
||
import ( | ||
"fmt" | ||
"encoding/json" | ||
) | ||
|
||
func F() error { | ||
a, err := json.Marshal(0) //@codeaction("a", end, "refactor.extract.function", out) | ||
if err != nil { | ||
return fmt.Errorf("1: %w", err) | ||
} | ||
b, err := json.Marshal(0) | ||
if err != nil { | ||
return fmt.Errorf("2: %w", err) | ||
} //@loc(end, "}") | ||
fmt.Println(a, b) | ||
return nil | ||
} | ||
|
||
-- @out/a.go -- | ||
package a | ||
|
||
import ( | ||
"fmt" | ||
"encoding/json" | ||
) | ||
|
||
func F() error { | ||
//@codeaction("a", end, "refactor.extract.function", out) | ||
a, b, shouldReturn, returnValue := newFunction() | ||
if shouldReturn { | ||
return returnValue | ||
} //@loc(end, "}") | ||
fmt.Println(a, b) | ||
return nil | ||
} | ||
|
||
func newFunction() ([]byte, []byte, bool, error) { | ||
a, err := json.Marshal(0) | ||
if err != nil { | ||
return nil, nil, true, fmt.Errorf("1: %w", err) | ||
} | ||
b, err := json.Marshal(0) | ||
if err != nil { | ||
return nil, nil, true, fmt.Errorf("2: %w", err) | ||
} | ||
return a, b, false, nil | ||
} | ||
|
This file contains 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