compiler: do not allocate slotes for unused "_" vars
This commit is contained in:
parent
0b44a43043
commit
18369c489e
3 changed files with 29 additions and 7 deletions
|
@ -255,3 +255,19 @@ func TestConstDontUseSlots(t *testing.T) {
|
|||
src := buf.String()
|
||||
eval(t, src, big.NewInt(count))
|
||||
}
|
||||
|
||||
func TestUnderscoreVarsDontUseSlots(t *testing.T) {
|
||||
const count = 128
|
||||
buf := bytes.NewBufferString("package foo\n")
|
||||
for i := 0; i < count; i++ {
|
||||
buf.WriteString(fmt.Sprintf("var _, n%d = 1, 1\n", i))
|
||||
}
|
||||
buf.WriteString("func Main() int { sum := 0\n")
|
||||
for i := 0; i < count; i++ {
|
||||
buf.WriteString(fmt.Sprintf("sum += n%d\n", i))
|
||||
}
|
||||
buf.WriteString("return sum }")
|
||||
|
||||
src := buf.String()
|
||||
eval(t, src, big.NewInt(count))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue