From 382449b1e3b51c7b0c5e14b86bbac8283272dde4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 4 Sep 2023 14:03:35 +0100 Subject: [PATCH] all: fix issues spotted by nilness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In loader.matchPackagesInFS, the error check mismatched the used error. Further down in the same func, a nil error case was impossible. In builder.finish, a nil check on t would never be true. Finally, in a test func, remove an impossible error comparison. For more information on what this go/analysis pass does, see https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/nilness. Signed-off-by: Daniel Martí Change-Id: Ic648103c96435bb1339a15268e6204c44fe533f3 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1168432 Reviewed-by: Roger Peppe TryBot-Result: CUEcueckoo Unity-Result: CUE porcuepine --- cue/load/search.go | 8 +++----- encoding/openapi/build.go | 3 --- tools/flow/flow_test.go | 3 +-- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/cue/load/search.go b/cue/load/search.go index 7d1e9fbfd03..c821d1b796d 100644 --- a/cue/load/search.go +++ b/cue/load/search.go @@ -188,9 +188,9 @@ func (l *loader) matchPackagesInFS(pattern, pkgName string) *match { // silently skipped as not matching the pattern. // Do not take root, as we want to stay relative // to one dir only. - relPath, e := filepath.Rel(c.Dir, path) - if e != nil { - panic(err) // Should never happen because c.Dir is absolute. + relPath, err2 := filepath.Rel(c.Dir, path) + if err2 != nil { + panic(err2) // Should never happen because c.Dir is absolute. } relPath = "./" + filepath.ToSlash(relPath) // TODO: consider not doing these checks here. @@ -199,8 +199,6 @@ func (l *loader) matchPackagesInFS(pattern, pkgName string) *match { for _, p := range pkgs { if err := p.Err; err != nil && (p == nil || len(p.InvalidFiles) == 0) { switch err.(type) { - case nil: - break case *NoFilesError: if c.DataFiles && len(p.OrphanedFiles) > 0 { break diff --git a/encoding/openapi/build.go b/encoding/openapi/build.go index b68b906c70d..bd8bb5fc48f 100644 --- a/encoding/openapi/build.go +++ b/encoding/openapi/build.go @@ -1237,9 +1237,6 @@ func (b *builder) finish() *ast.StructLit { default: exprs := []ast.Expr{} - if t != nil { - exprs = append(exprs, (*ast.StructLit)(t)) - } for _, s := range b.allOf { exprs = append(exprs, s) } diff --git a/tools/flow/flow_test.go b/tools/flow/flow_test.go index 6979847ef92..7cb43f04c42 100644 --- a/tools/flow/flow_test.go +++ b/tools/flow/flow_test.go @@ -165,8 +165,7 @@ func taskFunc(v cue.Value) (flow.Runner, error) { t.Fill(map[string]string{"stdout": "foo"}) return nil }), nil - } - if err != nil && v.LookupPath(cue.MakePath(cue.Str("$id"))).Exists() { + } else if v.LookupPath(cue.MakePath(cue.Str("$id"))).Exists() { return nil, err }