...
Run Format

Source file test/fixedbugs/issue19710.go

Documentation: test/fixedbugs

     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  }
    26  

View as plain text