Skip to content

Commit 3be6386

Browse files
committed
Code style: remove repeated helper functions
1 parent 25690fe commit 3be6386

File tree

3 files changed

+3
-21
lines changed

3 files changed

+3
-21
lines changed

checker/nature/nature.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ type Nature struct {
2525
FieldIndex []int // Index of field in type.
2626
}
2727

28-
func (n Nature) IsNil() bool {
29-
return n.Nil
30-
}
31-
3228
func (n Nature) IsAny() bool {
3329
return n.Kind() == reflect.Interface && n.NumMethods() == 0
3430
}
@@ -37,7 +33,7 @@ func (n Nature) IsUnknown() bool {
3733
switch {
3834
case n.Type == nil && !n.Nil:
3935
return true
40-
case isAny(n):
36+
case n.IsAny():
4137
return true
4238
}
4339
return false
@@ -92,7 +88,7 @@ func (n Nature) Elem() Nature {
9288
func (n Nature) AssignableTo(nt Nature) bool {
9389
if n.Nil {
9490
// Untyped nil is assignable to any interface, but implements only the empty interface.
95-
if isAny(nt) {
91+
if nt.IsAny() {
9692
return true
9793
}
9894
}

checker/nature/utils.go

-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import (
66
"github.com/expr-lang/expr/internal/deref"
77
)
88

9-
func isAny(nt Nature) bool {
10-
return nt.Kind() == reflect.Interface && nt.NumMethods() == 0
11-
}
12-
139
func fieldName(field reflect.StructField) string {
1410
if taggedName := field.Tag.Get("expr"); taggedName != "" {
1511
return taggedName

checker/types.go

+1-11
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,7 @@ func or(l, r Nature, fns ...func(Nature) bool) bool {
7171
}
7272

7373
func isUnknown(nt Nature) bool {
74-
switch {
75-
case nt.Type == nil && !nt.Nil:
76-
return true
77-
case isAny(nt):
78-
return true
79-
}
80-
return false
81-
}
82-
83-
func isAny(nt Nature) bool {
84-
return nt.Kind() == reflect.Interface && nt.NumMethods() == 0
74+
return nt.IsUnknown()
8575
}
8676

8777
func isInteger(nt Nature) bool {

0 commit comments

Comments
 (0)