mirror of
https://github.com/MontFerret/ferret.git
synced 2025-04-21 12:16:53 +02:00
feat(runtime): check Kind() by 0 or Interface() panic (#587)
This commit is contained in:
parent
dd0e9ee8ae
commit
cd35437452
@ -145,4 +145,28 @@ func TestParam(t *testing.T) {
|
|||||||
So(err, ShouldNotBeNil)
|
So(err, ShouldNotBeNil)
|
||||||
So(err.Error(), ShouldContainSubstring, "subattr")
|
So(err.Error(), ShouldContainSubstring, "subattr")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("Should be possible to use in struct with nested struct which nil", t, func() {
|
||||||
|
type Some2 struct {
|
||||||
|
}
|
||||||
|
type Some struct {
|
||||||
|
Some2 *Some2
|
||||||
|
}
|
||||||
|
|
||||||
|
someObj := &Some{}
|
||||||
|
prog := compiler.New().
|
||||||
|
MustCompile(`
|
||||||
|
|
||||||
|
RETURN null
|
||||||
|
`)
|
||||||
|
|
||||||
|
panics := func() {
|
||||||
|
_, _ = prog.Run(
|
||||||
|
context.Background(),
|
||||||
|
runtime.WithParam("struct", someObj),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
So(panics, ShouldNotPanic)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,13 @@ func Parse(input interface{}) core.Value {
|
|||||||
kind := t.Kind()
|
kind := t.Kind()
|
||||||
|
|
||||||
if kind == reflect.Ptr {
|
if kind == reflect.Ptr {
|
||||||
return Parse(v.Elem().Interface())
|
el := v.Elem()
|
||||||
|
|
||||||
|
if el.Kind() == 0 {
|
||||||
|
return None
|
||||||
|
}
|
||||||
|
|
||||||
|
return Parse(el.Interface())
|
||||||
}
|
}
|
||||||
|
|
||||||
if kind == reflect.Slice || kind == reflect.Array {
|
if kind == reflect.Slice || kind == reflect.Array {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user