Skip to content

Commit

Permalink
all: fix issues spotted by nilness
Browse files Browse the repository at this point in the history
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í <mvdan@mvdan.cc>
Change-Id: Ic648103c96435bb1339a15268e6204c44fe533f3
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1168432
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
  • Loading branch information
mvdan committed Sep 5, 2023
1 parent fe2f216 commit 382449b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
8 changes: 3 additions & 5 deletions cue/load/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions encoding/openapi/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions tools/flow/flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 382449b

Please sign in to comment.