Skip to content

Commit d5e01c0

Browse files
committed
test: add test of deferred delete
Updates #19710 Change-Id: I37d19a4a02b9010cb5f9062b3d141d5d65e12e01 Reviewed-on: https://go-review.googlesource.com/43497 Run-TryBot: Josh Bleecher Snyder <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 67e4712 commit d5e01c0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

test/fixedbugs/issue19710.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// run
2+
3+
// Copyright 2017 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Issue 19710: mishandled defer delete(...)
8+
9+
package main
10+
11+
func main() {
12+
if n := len(f()); n != 0 {
13+
println("got", n, "want 0")
14+
panic("bad defer delete")
15+
}
16+
}
17+
18+
func f() map[int]bool {
19+
m := map[int]bool{}
20+
for i := 0; i < 3; i++ {
21+
m[i] = true
22+
defer delete(m, i)
23+
}
24+
return m
25+
}

0 commit comments

Comments
 (0)