github.com/golangci/go-tools@v0.0.0-20190318060251-af6baa5dc196/staticcheck/testdata/src/CheckDiffSizeComparison/CheckDiffSizeComparison.go (about) 1 package pkg 2 3 func fn1() { 4 var s1 = "foobar" 5 _ = "a"[:] == s1 // MATCH /comparing strings of different sizes/ 6 _ = s1 == "a"[:] // MATCH /comparing strings of different sizes/ 7 _ = "a"[:] == s1[:2] // MATCH /comparing strings of different sizes/ 8 _ = "ab"[:] == s1[1:2] // MATCH /comparing strings of different sizes/ 9 _ = "ab"[:] == s1[0+1:2] // MATCH /comparing strings of different sizes/ 10 _ = "a"[:] == "abc" // MATCH /comparing strings of different sizes/ 11 _ = "a"[:] == "a"+"bc" // MATCH /comparing strings of different sizes/ 12 _ = "foobar"[:] == s1+"bc" // MATCH /comparing strings of different sizes/ 13 _ = "a"[:] == "abc"[:] // MATCH /comparing strings of different sizes/ 14 _ = "a"[:] == "abc"[:2] // MATCH /comparing strings of different sizes/ 15 16 _ = "a" == s1 // ignores 17 _ = s1 == "a" // ignored 18 _ = "abcdef"[:] == s1 19 _ = "ab"[:] == s1[:2] 20 _ = "a"[:] == s1[1:2] 21 _ = "a"[:] == s1[0+1:2] 22 _ = "abc"[:] == "abc" 23 _ = "abc"[:] == "a"+"bc" 24 _ = s1[:] == "foo"+"bar" 25 _ = "abc"[:] == "abc"[:] // MATCH /identical expressions on the left and right side/ 26 _ = "ab"[:] == "abc"[:2] 27 } 28 29 func fn2() { 30 s1 := "123" 31 if true { 32 s1 = "1234" 33 } 34 35 _ = s1 == "12345"[:] // MATCH /comparing strings of different sizes/ 36 _ = s1 == "1234"[:] 37 _ = s1 == "123"[:] 38 _ = s1 == "12"[:] // MATCH /comparing strings of different sizes/ 39 } 40 41 func fn3(x string) { 42 switch x[:1] { 43 case "a": 44 case "ab": // MATCH /comparing strings of different sizes/ 45 case "b": 46 case "bc": // MATCH /comparing strings of different sizes/ 47 } 48 }