blob: 2c60846a807ccaa7892b0aa33b9e60d868ea481e [file] [log] [blame]
This test verifies the fix for golang/go#70563: refactor.extract.variable
inserts new statement before the scope of its free symbols.
-- flags --
-ignore_extra_diags
-- inside_else.go --
package extract
func _() {
if x := 1; true {
} else if y := x + 1; true { //@codeaction("x + 1", "refactor.extract.variable", err=re"else-if's init has free variable")
}
}
-- inside_case.go --
package extract
func _() {
switch x := 1; x {
case x + 1: //@codeaction("x + 1", "refactor.extract.variable-all", err=re"switch's init has free variable")
y := x + 1 //@codeaction("x + 1", "refactor.extract.variable-all", err=re"switch's init has free variable")
_ = y
case 3:
y := x + 1 //@codeaction("x + 1", "refactor.extract.variable-all", err=re"switch's init has free variable")
_ = y
}
}
-- parent_if.go --
package extract
func _() {
if x := 1; x > 0 {
y = x + 1 //@codeaction("x + 1", "refactor.extract.variable-all", err=re"if-statement's init has free variable")
} else {
y = x + 1 //@codeaction("x + 1", "refactor.extract.variable-all", err=re"if-statement's init has free variable")
}
}
-- parent_switch.go --
package extract
func _() {
switch x := 1; x {
case 1:
y = x + 1 //@codeaction("x + 1", "refactor.extract.variable-all", err=re"switch's init has free variable")
case 3:
y = x + 1 //@codeaction("x + 1", "refactor.extract.variable-all", err=re"switch's init has free variable")
}
}