From: Daniel Martí Date: Mon, 11 Jun 2018 08:34:57 +0000 (+0100) Subject: cmd/vet: simplify side effects func call logic X-Git-Tag: go1.11beta1~90 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=26727b84d92db09843175a945b93ad46ff7d0a53;p=gostls13.git cmd/vet: simplify side effects func call logic Instead of first looking for values of unnamed signature type, first treat the types and builtins. All the remaining cases will be what we're after. Change-Id: I328e22ae0be1cccaeb45ed4ddaa360233d447e7e Reviewed-on: https://go-review.googlesource.com/117835 Run-TryBot: Daniel Martí Reviewed-by: Robert Griesemer --- diff --git a/src/cmd/vet/bool.go b/src/cmd/vet/bool.go index e8b73175aa..1cd477f988 100644 --- a/src/cmd/vet/bool.go +++ b/src/cmd/vet/bool.go @@ -9,7 +9,6 @@ package main import ( "go/ast" "go/token" - "go/types" ) func init() { @@ -142,28 +141,22 @@ func hasSideEffects(f *File, e ast.Expr) bool { ast.Inspect(e, func(node ast.Node) bool { switch n := node.(type) { case *ast.CallExpr: - // Don't call Type.Underlying(), since its lack - // lets us see the NamedFuncType(x) type - // conversion as a *types.Named. typVal := f.pkg.types[n.Fun] - _, isSig := typVal.Type.(*types.Signature) switch { - case typVal.IsValue() && isSig: - // If we have a value of unnamed signature type, - // this CallExpr is a non-builtin func call and - // not a type conversion. Conservatively assume - // that all function and method calls have side - // effects for now. + case typVal.IsType(): + // Type conversion, which is safe. + case typVal.IsBuiltin(): + // Builtin func, conservatively assumed to not + // be safe for now. safe = false return false - case typVal.IsBuiltin(): - // For now, conservatively assume that all - // built-in functions have side effects. + default: + // A non-builtin func or method call. + // Conservatively assume that all of them have + // side effects for now. safe = false return false } - // It's a type conversion, which cannot - // have side effects. case *ast.UnaryExpr: if n.Op == token.ARROW { safe = false