diff --git a/expr_test.go b/expr_test.go index 57d2cfbbb..8214b954c 100644 --- a/expr_test.go +++ b/expr_test.go @@ -2765,3 +2765,20 @@ func TestMemoryBudget(t *testing.T) { }) } } + +func TestIssue802(t *testing.T) { + prog, err := expr.Compile(`arr[1:2][0]`) + if err != nil { + t.Fatalf("error compiling program: %v", err) + } + val, err := expr.Run(prog, map[string]any{ + "arr": [5]int{0, 1, 2, 3, 4}, + }) + if err != nil { + t.Fatalf("error running program: %v", err) + } + valInt, ok := val.(int) + if !ok || valInt != 1 { + t.Fatalf("invalid result, expected 1, got %v", val) + } +} diff --git a/vm/runtime/runtime.go b/vm/runtime/runtime.go index cd48a280d..ccd499e0e 100644 --- a/vm/runtime/runtime.go +++ b/vm/runtime/runtime.go @@ -162,6 +162,11 @@ func Slice(array, from, to any) any { if a > b { a = b } + if v.Kind() == reflect.Array && !v.CanAddr() { + newValue := reflect.New(v.Type()).Elem() + newValue.Set(v) + v = newValue + } value := v.Slice(a, b) if value.IsValid() { return value.Interface()