| 1 |
This test verifies the fix for golang/go#73972: extraction should |
| 2 |
not modify the return statements of anonymous functions. |
| 3 |
|
| 4 |
-- go.mod -- |
| 5 |
module mod.test/extract |
| 6 |
|
| 7 |
go 1.18 |
| 8 |
|
| 9 |
-- a.go -- |
| 10 |
package extract |
| 11 |
|
| 12 |
import ( |
| 13 |
"fmt" |
| 14 |
"strings" |
| 15 |
) |
| 16 |
|
| 17 |
func main() { |
| 18 |
b := strings.ContainsFunc("a", func(_ rune) bool { //@codeaction("b", "refactor.extract.function", end=end, result=ext) |
| 19 |
return false |
| 20 |
}) |
| 21 |
if b { |
| 22 |
return |
| 23 |
} //@loc(end, "}") |
| 24 |
fmt.Println(b) |
| 25 |
} |
| 26 |
|
| 27 |
-- @ext/a.go -- |
| 28 |
package extract |
| 29 |
|
| 30 |
import ( |
| 31 |
"fmt" |
| 32 |
"strings" |
| 33 |
) |
| 34 |
|
| 35 |
func main() { |
| 36 |
b, shouldReturn := newFunction() |
| 37 |
if shouldReturn { |
| 38 |
return |
| 39 |
} //@loc(end, "}") |
| 40 |
fmt.Println(b) |
| 41 |
} |
| 42 |
|
| 43 |
func newFunction() (bool, bool) { |
| 44 |
b := strings.ContainsFunc("a", func(_ rune) bool { //@codeaction("b", "refactor.extract.function", end=end, result=ext) |
| 45 |
return false |
| 46 |
}) |
| 47 |
if b { |
| 48 |
return false, true |
| 49 |
} |
| 50 |
return b, false |
| 51 |
} |
| 52 |
|