Skip to content

Commit 382449b

Browse files
committed
all: fix issues spotted by nilness
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í <[email protected]> Change-Id: Ic648103c96435bb1339a15268e6204c44fe533f3 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1168432 Reviewed-by: Roger Peppe <[email protected]> TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent fe2f216 commit 382449b

File tree

3 files changed

+4
-10
lines changed

3 files changed

+4
-10
lines changed

cue/load/search.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ func (l *loader) matchPackagesInFS(pattern, pkgName string) *match {
188188
// silently skipped as not matching the pattern.
189189
// Do not take root, as we want to stay relative
190190
// to one dir only.
191-
relPath, e := filepath.Rel(c.Dir, path)
192-
if e != nil {
193-
panic(err) // Should never happen because c.Dir is absolute.
191+
relPath, err2 := filepath.Rel(c.Dir, path)
192+
if err2 != nil {
193+
panic(err2) // Should never happen because c.Dir is absolute.
194194
}
195195
relPath = "./" + filepath.ToSlash(relPath)
196196
// TODO: consider not doing these checks here.
@@ -199,8 +199,6 @@ func (l *loader) matchPackagesInFS(pattern, pkgName string) *match {
199199
for _, p := range pkgs {
200200
if err := p.Err; err != nil && (p == nil || len(p.InvalidFiles) == 0) {
201201
switch err.(type) {
202-
case nil:
203-
break
204202
case *NoFilesError:
205203
if c.DataFiles && len(p.OrphanedFiles) > 0 {
206204
break

encoding/openapi/build.go

-3
Original file line numberDiff line numberDiff line change
@@ -1237,9 +1237,6 @@ func (b *builder) finish() *ast.StructLit {
12371237

12381238
default:
12391239
exprs := []ast.Expr{}
1240-
if t != nil {
1241-
exprs = append(exprs, (*ast.StructLit)(t))
1242-
}
12431240
for _, s := range b.allOf {
12441241
exprs = append(exprs, s)
12451242
}

tools/flow/flow_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ func taskFunc(v cue.Value) (flow.Runner, error) {
165165
t.Fill(map[string]string{"stdout": "foo"})
166166
return nil
167167
}), nil
168-
}
169-
if err != nil && v.LookupPath(cue.MakePath(cue.Str("$id"))).Exists() {
168+
} else if v.LookupPath(cue.MakePath(cue.Str("$id"))).Exists() {
170169
return nil, err
171170
}
172171

0 commit comments

Comments
 (0)