Commit c8a98d0 1 parent 29ec1fb commit c8a98d0 Copy full SHA for c8a98d0
File tree 3 files changed +11
-4
lines changed
3 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -93,10 +93,11 @@ func (vm *VM) MustWarmUp(structOrStructPtr ...interface{}) {
93
93
// If the structure type has not been warmed up,
94
94
// it will be slower when it is first called.
95
95
func (vm * VM ) Run (structOrStructPtr interface {}) (* TagExpr , error ) {
96
- if structOrStructPtr == nil {
97
- return nil , errors .New ("cannot run nil interface" )
96
+ u := tpack .Unpack (structOrStructPtr )
97
+ if u .IsNil () {
98
+ return nil , errors .New ("cannot run nil data" )
98
99
}
99
- u := tpack . Unpack ( structOrStructPtr ) .UnderlyingElem ()
100
+ u = u .UnderlyingElem ()
100
101
tid := u .RuntimeTypeID ()
101
102
var err error
102
103
vm .rw .RLock ()
@@ -276,7 +277,7 @@ func (f *fieldVM) packElemFrom(ptr uintptr) reflect.Value {
276
277
func (s * structVM ) setIfaceTagExprGetter (f * fieldVM ) {
277
278
s .ifaceTagExprGetters = append (s .ifaceTagExprGetters , func (ptr uintptr ) (* TagExpr , bool ) {
278
279
v := f .packElemFrom (ptr )
279
- if ! v .IsValid () {
280
+ if ! v .IsValid () || v . IsNil () {
280
281
return nil , false
281
282
}
282
283
te , ok := s .vm .runFromValue (v )
Original file line number Diff line number Diff line change @@ -89,6 +89,8 @@ func Example() {
89
89
f := &F{}
90
90
f.f .g = 10
91
91
fmt.Println (vd.Validate (f))
92
+ f = nil
93
+ fmt.Println (vd.Validate (f))
92
94
93
95
// Output:
94
96
// true
@@ -98,6 +100,7 @@ func Example() {
98
100
// invalid d: [x y]
99
101
// invalid parameter: e
100
102
// {"succ":false, "error":"invalid parameter: f.g"}
103
+ // cannot run nil data
101
104
}
102
105
```
103
106
Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ func Example() {
71
71
f := & F {}
72
72
f .f .g = 10
73
73
fmt .Println (vd .Validate (f ))
74
+ f = nil
75
+ fmt .Println (vd .Validate (f ))
74
76
75
77
// Output:
76
78
// true
@@ -80,4 +82,5 @@ func Example() {
80
82
// invalid d: [x y]
81
83
// invalid parameter: e
82
84
// {"succ":false, "error":"invalid parameter: f.g"}
85
+ // cannot run nil data
83
86
}
You can’t perform that action at this time.
0 commit comments