Skip to content

Commit 58cbd0c

Browse files
committed
all: use reflect.TypeAssert in three more places
Others still use reflect.Value.Interface, but these are the ones that map to reflect.TypeAssert directly. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I7ac2bc7b9e1b689e21e4b68331f26fac74bf2784 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1231001 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent ec3e289 commit 58cbd0c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

cue/decode.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,8 @@ func (d *decoder) convertMap(x reflect.Value, v Value) {
385385
kt := t.Key()
386386
if reflect.PointerTo(kt).Implements(textUnmarshalerType) {
387387
kv = reflect.New(kt)
388-
err := kv.Interface().(encoding.TextUnmarshaler).UnmarshalText([]byte(key))
388+
u, _ := reflect.TypeAssert[encoding.TextUnmarshaler](kv)
389+
err := u.UnmarshalText([]byte(key))
389390
d.addErr(err)
390391
kv = kv.Elem()
391392
} else {

internal/astinternal/debug.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (d *debugPrinter) value0(v reflect.Value, impliedType reflect.Type) {
104104
return
105105
}
106106
if k == reflect.Pointer {
107-
if n, ok := v.Interface().(ast.Node); ok {
107+
if n, ok := reflect.TypeAssert[ast.Node](v); ok {
108108
ptrVal = v.Pointer()
109109
if id, ok := d.nodeRefs[n]; ok {
110110
refName = refIDToName(id)
@@ -259,8 +259,7 @@ func (d *debugPrinter) structFields(v reflect.Value) (anyElems bool) {
259259
d.truncate(elemStart)
260260
}
261261
}
262-
val := v.Addr().Interface()
263-
if val, ok := val.(ast.Node); ok {
262+
if val, ok := reflect.TypeAssert[ast.Node](v.Addr()); ok {
264263
// Comments attached to a node aren't a regular field, but are still useful.
265264
// The majority of nodes won't have comments, so skip them when empty.
266265
if comments := ast.Comments(val); len(comments) > 0 {

0 commit comments

Comments
 (0)