Source file test/fixedbugs/issue13480.go

     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|operator \=\= not defined for .|cannot compare"
    22  	_ = S(nil) == s // ERROR "compare.*to nil|operator \=\= not defined for .|cannot compare"
    23  	switch s {
    24  	case S(nil): // ERROR "compare.*to nil|operator \=\= not defined for .|cannot compare"
    25  	}
    26  
    27  	_ = m == M(nil) // ERROR "compare.*to nil|operator \=\= not defined for .|cannot compare"
    28  	_ = M(nil) == m // ERROR "compare.*to nil|operator \=\= not defined for .|cannot compare"
    29  	switch m {
    30  	case M(nil): // ERROR "compare.*to nil|operator \=\= not defined for .|cannot compare"
    31  	}
    32  
    33  	_ = f == F(nil) // ERROR "compare.*to nil|operator \=\= not defined for .|cannot compare"
    34  	_ = F(nil) == f // ERROR "compare.*to nil|operator \=\= not defined for .|cannot compare"
    35  	switch f {
    36  	case F(nil): // ERROR "compare.*to nil|operator \=\= not defined for .|cannot compare"
    37  	}
    38  }
    39  

View as plain text