modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue19359.go (about)

     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  package main
     8  
     9  import "fmt"
    10  
    11  func set(m map[interface{}]interface{}, key interface{}) (err error) {
    12  	defer func() {
    13  		if r := recover(); r != nil {
    14  			err = fmt.Errorf("set failed: %v", r)
    15  		}
    16  	}()
    17  	m[key] = nil
    18  	return nil
    19  }
    20  
    21  func del(m map[interface{}]interface{}, key interface{}) (err error) {
    22  	defer func() {
    23  		if r := recover(); r != nil {
    24  			err = fmt.Errorf("del failed: %v", r)
    25  		}
    26  	}()
    27  	delete(m, key)
    28  	return nil
    29  }
    30  
    31  func main() {
    32  	m := make(map[interface{}]interface{})
    33  	set(m, []int{1, 2, 3})
    34  	set(m, "abc") // used to throw
    35  	del(m, []int{1, 2, 3})
    36  	del(m, "abc") // used to throw
    37  }