Skip to content

Commit ffafd61

Browse files
committed
all: remove a few unused parameters spotted by unparam
While here, apply three other tiny cleanups suggested by gopls: remove redundant returns and a redundant type in a declaration, and remove an unused field. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I93d5909fdb17c03d336e11b87667419b39e10d03 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201759 Reviewed-by: Roger Peppe <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 222b689 commit ffafd61

File tree

7 files changed

+15
-25
lines changed

7 files changed

+15
-25
lines changed

cue/errors.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"cuelang.org/go/cue/errors"
1919
"cuelang.org/go/cue/token"
2020
"cuelang.org/go/internal/core/adt"
21-
"cuelang.org/go/internal/core/runtime"
2221
)
2322

2423
func (v Value) toErr(b *adt.Bottom) (err errors.Error) {
@@ -96,7 +95,7 @@ var errNotExists = &adt.Bottom{
9695
Err: errors.Newf(token.NoPos, "undefined value"),
9796
}
9897

99-
func mkErr(idx *runtime.Runtime, src adt.Node, args ...interface{}) *adt.Bottom {
98+
func mkErr(src adt.Node, args ...interface{}) *adt.Bottom {
10099
var e *adt.Bottom
101100
var code adt.ErrorCode = -1
102101
outer:

cue/load/loader_common.go

-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ func (fp *fileProcessor) add(root string, file *build.File, mode importMode) {
180180
fp.err = errors.Append(fp.err, err)
181181
file.ExcludeReason = fp.err
182182
p.InvalidFiles = append(p.InvalidFiles, file)
183-
return
184183
}
185184
if err := setFileSource(fp.c, file); err != nil {
186185
badFile(errors.Promote(err, ""))

cue/query.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ outer:
7474
if err, ok := sel.sel.(pathError); ok {
7575
x = &adt.Bottom{Err: err.Error}
7676
} else {
77-
x = mkErr(v.idx, n, adt.EvalError, "field not found: %v", sel.sel)
77+
x = mkErr(n, adt.EvalError, "field not found: %v", sel.sel)
7878
if n.Accept(ctx, f) {
7979
x.Code = adt.IncompleteError
8080
}

cue/types.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (o *hiddenStructValue) Lookup(key string) Value {
127127
}
128128
}
129129
if i == len {
130-
x := mkErr(o.v.idx, o.obj, 0, "field not found: %v", key)
130+
x := mkErr(o.obj, 0, "field not found: %v", key)
131131
x.NotExists = true
132132
// TODO: more specifically we should test whether the values that
133133
// are addressable from the root of the configuration can support the
@@ -180,7 +180,7 @@ func toMarshalErr(v Value, b *adt.Bottom) error {
180180

181181
func marshalErrf(v Value, src adt.Node, code adt.ErrorCode, msg string, args ...interface{}) error {
182182
arguments := append([]interface{}{code, msg}, args...)
183-
b := mkErr(v.idx, src, arguments...)
183+
b := mkErr(src, arguments...)
184184
return toMarshalErr(v, b)
185185
}
186186

@@ -962,8 +962,7 @@ func (v Value) Syntax(opts ...Option) ast.Node {
962962
if v.v == nil {
963963
return nil
964964
}
965-
var o options = getOptions(opts)
966-
// var inst *Instance
965+
o := getOptions(opts)
967966

968967
p := export.Profile{
969968
Simplify: !o.raw,
@@ -1251,11 +1250,11 @@ func (v Value) checkKind(ctx *adt.OpContext, want adt.Kind) *adt.Bottom {
12511250
k := x.Kind()
12521251
if want != adt.BottomKind {
12531252
if k&want == adt.BottomKind {
1254-
return mkErr(v.idx, x, "cannot use value %v (type %s) as %s",
1253+
return mkErr(x, "cannot use value %v (type %s) as %s",
12551254
ctx.Str(x), k, want)
12561255
}
12571256
if !adt.IsConcrete(x) {
1258-
return mkErr(v.idx, x, adt.IncompleteError, "non-concrete value %v", k)
1257+
return mkErr(x, adt.IncompleteError, "non-concrete value %v", k)
12591258
}
12601259
}
12611260
return nil
@@ -1298,7 +1297,7 @@ func (v Value) Len() Value {
12981297
}
12991298
}
13001299
const msg = "len not supported for type %v"
1301-
return remakeValue(v, nil, mkErr(v.idx, v.v, msg, v.Kind()))
1300+
return remakeValue(v, nil, mkErr(v.v, msg, v.Kind()))
13021301

13031302
}
13041303

@@ -1735,7 +1734,7 @@ func (v Value) FillPath(p Path, x interface{}) Value {
17351734
}
17361735
ctx := v.ctx()
17371736
if err := p.Err(); err != nil {
1738-
return newErrValue(v, mkErr(v.idx, nil, 0, "invalid path: %v", err))
1737+
return newErrValue(v, mkErr(nil, 0, "invalid path: %v", err))
17391738
}
17401739
var expr adt.Expr
17411740
switch x := x.(type) {

internal/astinternal/debug.go

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package astinternal
1717
import (
1818
"fmt"
1919
gotoken "go/token"
20-
"io"
2120
"reflect"
2221
"strconv"
2322
"strings"
@@ -52,7 +51,6 @@ type DebugConfig struct {
5251
}
5352

5453
type debugPrinter struct {
55-
w io.Writer
5654
buf []byte
5755
cfg DebugConfig
5856
level int

internal/core/adt/unify.go

-2
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,6 @@ func (n *nodeContext) completeNodeTasks(mode runMode) {
426426

427427
cc.decDependent(n.ctx, ROOT, nil) // REF(decrement:nodeDone)
428428
}
429-
430-
return
431429
}
432430

433431
func (n *nodeContext) updateScalar() {

internal/encoding/encoder.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ func (e Encoder) Close() error {
6969

7070
// NewEncoder writes content to the file with the given specification.
7171
func NewEncoder(ctx *cue.Context, f *build.File, cfg *Config) (*Encoder, error) {
72-
w, close, err := writer(f, cfg)
73-
if err != nil {
74-
return nil, err
75-
}
72+
w, close := writer(f, cfg)
7673
e := &Encoder{
7774
ctx: ctx,
7875
cfg: cfg,
@@ -290,16 +287,16 @@ func (e *Encoder) encodeFile(f *ast.File, interpret func(cue.Value) (*ast.File,
290287
return e.encValue(v)
291288
}
292289

293-
func writer(f *build.File, cfg *Config) (_ io.Writer, close func() error, err error) {
290+
func writer(f *build.File, cfg *Config) (_ io.Writer, close func() error) {
294291
if cfg.Out != nil {
295-
return cfg.Out, nil, nil
292+
return cfg.Out, nil
296293
}
297294
path := f.Filename
298295
if path == "-" {
299296
if cfg.Stdout == nil {
300-
return os.Stdout, nil, nil
297+
return os.Stdout, nil
301298
}
302-
return cfg.Stdout, nil, nil
299+
return cfg.Stdout, nil
303300
}
304301
// Delay opening the file until we can write it to completion.
305302
// This prevents clobbering the file in case of a crash.
@@ -323,5 +320,5 @@ func writer(f *build.File, cfg *Config) (_ io.Writer, close func() error, err er
323320
}
324321
return err
325322
}
326-
return b, fn, nil
323+
return b, fn
327324
}

0 commit comments

Comments
 (0)