diff --git a/src/cmd/vet/bool.go b/src/cmd/vet/bool.go index 31e81ec4bf..67321c3df4 100644 --- a/src/cmd/vet/bool.go +++ b/src/cmd/vet/bool.go @@ -145,13 +145,14 @@ func hasSideEffects(f *File, e ast.Expr) bool { // Don't call Type.Underlying(), since its lack // lets us see the NamedFuncType(x) type // conversion as a *types.Named. - _, ok := f.pkg.types[n.Fun].Type.(*types.Signature) - if ok { - // Conservatively assume that all function and - // method calls have side effects for - // now. This will include func type - // conversions, but it's ok given that - // this is the conservative side. + typVal := f.pkg.types[n.Fun] + _, isSig := typVal.Type.(*types.Signature) + if typVal.IsValue() && isSig { + // If we have a value of unnamed signature type, + // this CallExpr is a func call and not a type + // conversion. Conservatively assume that all + // function and method calls have side effects + // for now. safe = false return false } diff --git a/src/cmd/vet/testdata/bool.go b/src/cmd/vet/testdata/bool.go index bada13ae0d..be78caac18 100644 --- a/src/cmd/vet/testdata/bool.go +++ b/src/cmd/vet/testdata/bool.go @@ -24,8 +24,7 @@ func RatherStupidConditions() { _ = i == T(2) || i == T(2) // ERROR "redundant or: i == T(2) || i == T(2)" _ = FT(f) == nil || FT(f) == nil // ERROR "redundant or: FT(f) == nil || FT(f) == nil" - // TODO: distinguish from an actual func call - _ = (func() int)(f) == nil || (func() int)(f) == nil + _ = (func() int)(f) == nil || (func() int)(f) == nil // ERROR "redundant or: (func() int)(f) == nil || (func() int)(f) == nil" var namedFuncVar FT _ = namedFuncVar() == namedFuncVar() // OK; still func calls