1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-04 10:35:08 +02:00

feat(runtime): check Kind() by 0 or Interface() panic (#587)

This commit is contained in:
Roman 2021-01-22 22:59:02 +03:00 committed by GitHub
parent dd0e9ee8ae
commit cd35437452
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -145,4 +145,28 @@ func TestParam(t *testing.T) {
So(err, ShouldNotBeNil)
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)
})
}

View File

@ -148,7 +148,13 @@ func Parse(input interface{}) core.Value {
kind := t.Kind()
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 {