Skip to content

Commit

Permalink
all: remove redundant interface type assertions
Browse files Browse the repository at this point in the history
These two are of the form:

	type T interface { ... }
	var v1 T
	v2 := v1.(T)

That is, if v1 is already of interface type T,
then the type assertion `.(T)` is unnecessary.
Found via staticcheck's S1040.

Change-Id: Icd57e251121cb1f646106115ab5c9f9cb40768bb
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/536097
Unity-Result: CUEcueckoo <cueckoo@cuelang.org>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
  • Loading branch information
mvdan committed Apr 27, 2022
1 parent 00c5ddf commit 74d55b7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/core/adt/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ func (n *nodeContext) getValidators() BaseValue {
v = &BasicType{K: n.kind}

case 1:
v = a[0].(Value) // remove cast
v = a[0]

default:
v = &Conjunction{Values: a}
Expand Down
10 changes: 2 additions & 8 deletions pkg/internal/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,15 @@ func (c *CallCtxt) invalidArgType(arg adt.Value, i int, typ string, err error) {
c.Err = b
return
}
v, ok := arg.(adt.Value)
// TODO: make these permanent errors if the value did not originate from
// a reference.
if !ok {
c.errf(nil,
"cannot use incomplete value %s as %s in argument %d to %s",
arg, typ, i, c.Name())
}
if err != nil {
c.errf(err,
"cannot use %s (type %s) as %s in argument %d to %s",
arg, v.Kind(), typ, i, c.Name())
arg, arg.Kind(), typ, i, c.Name())
} else {
c.errf(err,
"cannot use %s (type %s) as %s in argument %d to %s",
arg, v.Kind(), typ, i, c.Name())
arg, arg.Kind(), typ, i, c.Name())
}
}

0 comments on commit 74d55b7

Please sign in to comment.