| 1 |
This test verifies the fix for golang/go#78142: a crash in function extraction |
| 2 |
when a function with no result types has a return statement. |
| 3 |
|
| 4 |
-- flags -- |
| 5 |
-ignore_extra_diags |
| 6 |
|
| 7 |
-- go.mod -- |
| 8 |
module mod.test/extract |
| 9 |
|
| 10 |
go 1.18 |
| 11 |
|
| 12 |
-- a.go -- |
| 13 |
package a |
| 14 |
|
| 15 |
func f() { |
| 16 |
var err error |
| 17 |
if err != nil { //@codeaction("if", "refactor.extract.function", end=ifend, edit=a) |
| 18 |
return err |
| 19 |
} //@loc(ifend, "}") |
| 20 |
println("reachable") |
| 21 |
} |
| 22 |
-- @a/a.go -- |
| 23 |
@@ -5,3 +5 @@ |
| 24 |
- if err != nil { //@codeaction("if", "refactor.extract.function", end=ifend, edit=a) |
| 25 |
- return err |
| 26 |
- } //@loc(ifend, "}") |
| 27 |
+ newFunction(err) //@loc(ifend, "}") |
| 28 |
@@ -10 +8,6 @@ |
| 29 |
+ |
| 30 |
+func newFunction(err error) { |
| 31 |
+ if err != nil { //@codeaction("if", "refactor.extract.function", end=ifend, edit=a) |
| 32 |
+ return err |
| 33 |
+ } |
| 34 |
+} |