...
Run Format

Source file src/cmd/vet/testdata/nilfunc.go

Documentation: cmd/vet/testdata

     1  // Copyright 2013 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package testdata
     6  
     7  func F() {}
     8  
     9  type T struct {
    10  	F func()
    11  }
    12  
    13  func (T) M() {}
    14  
    15  var Fv = F
    16  
    17  func Comparison() {
    18  	var t T
    19  	var fn func()
    20  	if fn == nil || Fv == nil || t.F == nil {
    21  		// no error; these func vars or fields may be nil
    22  	}
    23  	if F == nil { // ERROR "comparison of function F == nil is always false"
    24  		panic("can't happen")
    25  	}
    26  	if t.M == nil { // ERROR "comparison of function M == nil is always false"
    27  		panic("can't happen")
    28  	}
    29  	if F != nil { // ERROR "comparison of function F != nil is always true"
    30  		if t.M != nil { // ERROR "comparison of function M != nil is always true"
    31  			return
    32  		}
    33  	}
    34  	panic("can't happen")
    35  }
    36  

View as plain text