github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/golang/lint/testdata/var-decl.go (about) 1 // Test for redundant type declaration. 2 3 // Package foo ... 4 package foo 5 6 import "fmt" 7 import "net/http" 8 9 // Q is a test type. 10 type Q bool 11 12 var myInt int = 7 // MATCH /should.*int.*myInt.*inferred/ 13 var mux *http.ServeMux = http.NewServeMux() // MATCH /should.*\*http\.ServeMux.*inferred/ 14 15 var myZeroInt int = 0 // MATCH /should.*= 0.*myZeroInt.*zero value/ 16 var myZeroFlt float32 = 0. // MATCH /should.*= 0\..*myZeroFlt.*zero value/ 17 var myZeroF64 float64 = 0.0 // MATCH /should.*= 0\..*myZeroF64.*zero value/ 18 var myZeroImg complex64 = 0i // MATCH /should.*= 0i.*myZeroImg.*zero value/ 19 var myZeroStr string = "" // MATCH /should.*= "".*myZeroStr.*zero value/ 20 var myZeroRaw string = `` // MATCH /should.*= ``.*myZeroRaw.*zero value/ 21 var myZeroPtr *Q = nil // MATCH /should.*= nil.*myZeroPtr.*zero value/ 22 var myZeroRune rune = '\x00' // MATCH /should.*= '\\x00'.*myZeroRune.*zero value/ 23 var myZeroRune2 rune = '\000' // MATCH /should.*= '\\000'.*myZeroRune2.*zero value/ 24 25 // No warning because there's no type on the LHS 26 var x = 0 27 28 // This shouldn't get a warning because there's no initial values. 29 var str fmt.Stringer 30 31 // No warning because this is a const. 32 const k uint64 = 7 33 34 const num = 123 35 36 // No warning because the var's RHS is known to be an untyped const. 37 var flags uint32 = num 38 39 // No warnings because the RHS is an ideal int, and the LHS is a different int type. 40 var userID int64 = 1235 41 var negID int64 = -1 42 var parenID int64 = (17) 43 var crazyID int64 = -(-(-(-9))) 44 45 // Same, but for strings and floats. 46 type stringT string 47 type floatT float64 48 49 var stringV stringT = "abc" 50 var floatV floatT = 123.45 51 52 // No warning because the LHS names an interface type. 53 var data interface{} = googleIPs 54 var googleIPs []int 55 56 // No warning because it's a common idiom for interface satisfaction. 57 var _ Server = (*serverImpl)(nil) 58 59 // Server is a test type. 60 type Server interface{} 61 type serverImpl struct{} 62 63 // LHS is a different type than the RHS. 64 var myStringer fmt.Stringer = q(0) 65 66 // We don't figure out the true types of LHS and RHS here, 67 // but io.Writer is a known weaker type for many common uses, 68 // so the suggestion should be suppressed here. 69 var out io.Writer = os.Stdout 70 71 // This next one, however, should be type checked. 72 var out2 io.Writer = newWriter() // MATCH /should.*io\.Writer/ 73 74 func newWriter() io.Writer { return nil } 75 76 var y string = q(1).String() // MATCH /should.*string/ 77 78 type q int 79 80 func (q) String() string { return "I'm a q" }