Skip to content

Commit feedcc8

Browse files
committed
Remove redundant check
1 parent bfe0e4a commit feedcc8

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

vm/runtime/runtime.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,15 @@ func FetchField(from interface{}, field *Field) interface{} {
7777
v = reflect.Indirect(v)
7878
kind = v.Kind()
7979
}
80-
if kind == reflect.Struct {
81-
// We can use v.FieldByIndex here, but it will panic if the field
82-
// is not exists. And we need to recover() to generate a more
83-
// user-friendly error message.
84-
// Also, our fieldByIndex() function is slightly faster than the
85-
// v.FieldByIndex() function as we don't need to verify what a field
86-
// is a struct as we already did it on compilation step.
87-
value := fieldByIndex(v, field.Index)
88-
if value.IsValid() {
89-
return value.Interface()
90-
}
80+
// We can use v.FieldByIndex here, but it will panic if the field
81+
// is not exists. And we need to recover() to generate a more
82+
// user-friendly error message.
83+
// Also, our fieldByIndex() function is slightly faster than the
84+
// v.FieldByIndex() function as we don't need to verify what a field
85+
// is a struct as we already did it on compilation step.
86+
value := fieldByIndex(v, field.Index)
87+
if value.IsValid() {
88+
return value.Interface()
9189
}
9290
}
9391
panic(fmt.Sprintf("cannot get %v from %T", field.Path, from))

0 commit comments

Comments
 (0)