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

     1  // errorcheck
     2  
     3  // Copyright 2015 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  // Verify that comparisons of slice/map/func values against converted nil
     8  // values are properly rejected.
     9  
    10  package p
    11  
    12  func bug() {
    13  	type S []byte
    14  	type M map[int]int
    15  	type F func()
    16  
    17  	var s S
    18  	var m M
    19  	var f F
    20  
    21  	_ = s == S(nil) // ERROR "compare.*to nil"
    22  	_ = S(nil) == s // ERROR "compare.*to nil"
    23  	switch s {
    24  	case S(nil): // ERROR "compare.*to nil"
    25  	}
    26  
    27  	_ = m == M(nil) // ERROR "compare.*to nil"
    28  	_ = M(nil) == m // ERROR "compare.*to nil"
    29  	switch m {
    30  	case M(nil): // ERROR "compare.*to nil"
    31  	}
    32  
    33  	_ = f == F(nil) // ERROR "compare.*to nil"
    34  	_ = F(nil) == f // ERROR "compare.*to nil"
    35  	switch f {
    36  	case F(nil): // ERROR "compare.*to nil"
    37  	}
    38  }