Skip to content

Commit f85b3f7

Browse files
adonovangopherbot
authored andcommitted
internal/refactor/inline: don't treat blanks as decls in declares()
Plus, a test. Change-Id: I9d3f4729c1b8da51d771442d9c3f5909f608591e Reviewed-on: https://go-review.googlesource.com/c/tools/+/534895 Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Alan Donovan <[email protected]>
1 parent 3484534 commit f85b3f7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

internal/refactor/inline/inline.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,6 +2622,7 @@ func declares(stmts []ast.Stmt) map[string]bool {
26222622
}
26232623
}
26242624
}
2625+
delete(names, "_")
26252626
return names
26262627
}
26272628

internal/refactor/inline/inline_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,17 @@ func TestBasics(t *testing.T) {
388388
`func _(ch chan int) { f(ch) }`,
389389
`func _(ch chan int) { <-(<-chan int)(ch) }`,
390390
},
391+
{
392+
// (a regression test for unnecessary braces)
393+
"In block elision, blank decls don't count when computing name conflicts.",
394+
`func f(x int) { var _ = x; var _ = 3 }`,
395+
`func _() { var _ = 1; f(2) }`,
396+
`func _() {
397+
var _ = 1
398+
var _ = 2
399+
var _ = 3
400+
}`,
401+
},
391402
})
392403
}
393404

0 commit comments

Comments
 (0)