Fixed a panic which was thrown when trying to dereference an nil object
This commit is contained in:
parent
da00d9c723
commit
505fd29032
|
@ -161,6 +161,10 @@ func fromGoValue(v any) (object, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fromGoReflectValue(resVal reflect.Value) (object, error) {
|
func fromGoReflectValue(resVal reflect.Value) (object, error) {
|
||||||
|
if !resVal.IsValid() {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
switch resVal.Kind() {
|
switch resVal.Kind() {
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
return listableProxyObject{resVal}, nil
|
return listableProxyObject{resVal}, nil
|
||||||
|
|
|
@ -531,6 +531,9 @@ func TestBuiltins_Index(t *testing.T) {
|
||||||
|
|
||||||
{desc: "go list 1", expr: `goList | index 0 This`, want: "thing 1\n"},
|
{desc: "go list 1", expr: `goList | index 0 This`, want: "thing 1\n"},
|
||||||
{desc: "go list 2", expr: `goList | index 1 This`, want: "thing 2\n"},
|
{desc: "go list 2", expr: `goList | index 1 This`, want: "thing 2\n"},
|
||||||
|
{desc: "go list 3", expr: `goList | index 2`, want: "(nil)\n"},
|
||||||
|
{desc: "go list 4", expr: `goList | index 2 This`, want: "(nil)\n"},
|
||||||
|
{desc: "go list 5", expr: `goList | index 30`, want: "(nil)\n"},
|
||||||
|
|
||||||
{desc: "go struct 1", expr: `goStruct | index Alpha`, want: "foo\n"},
|
{desc: "go struct 1", expr: `goStruct | index Alpha`, want: "foo\n"},
|
||||||
{desc: "go struct 2", expr: `goStruct | index Beta`, want: "bar\n"},
|
{desc: "go struct 2", expr: `goStruct | index Beta`, want: "bar\n"},
|
||||||
|
@ -562,6 +565,7 @@ func TestBuiltins_Index(t *testing.T) {
|
||||||
return []*nest{
|
return []*nest{
|
||||||
{This: "thing 1"},
|
{This: "thing 1"},
|
||||||
{This: "thing 2"},
|
{This: "thing 2"},
|
||||||
|
nil,
|
||||||
}, nil
|
}, nil
|
||||||
})
|
})
|
||||||
inst.SetBuiltin("goStruct", func(ctx context.Context, args CallArgs) (any, error) {
|
inst.SetBuiltin("goStruct", func(ctx context.Context, args CallArgs) (any, error) {
|
||||||
|
|
Loading…
Reference in a new issue