diff options
| author | Marc Vertes <mvertes@free.fr> | 2026-01-14 18:44:17 +0100 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2026-01-14 18:44:17 +0100 |
| commit | 31e3793202402fda21905027c18ebfa5c8d8c832 (patch) | |
| tree | dbe52ae31fada099bc65fcd9c7d61f6266c6ba78 /interp/interpreter_test.go | |
| parent | de3baf0e06862f0420950f025b3328068f3b6df2 (diff) | |
fix: improve handling of indirections
Added 2 VM instructions, FnewE variant of Fnew with a dereference,
and FieldE, variant of Field with dereference.
It's now possible to pointers in structs and literal composites.
Diffstat (limited to 'interp/interpreter_test.go')
| -rw-r--r-- | interp/interpreter_test.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/interp/interpreter_test.go b/interp/interpreter_test.go index 0cb4160..bf90357 100644 --- a/interp/interpreter_test.go +++ b/interp/interpreter_test.go @@ -214,6 +214,8 @@ func TestStruct(t *testing.T) { {src: "type T struct {a string; b, c int}; var t T; t", res: "{ 0 0}"}, // #00 {src: "type T struct {a int}; var t T; t.a", res: "0"}, // #01 {src: "type T struct {a int}; var t T; t.a = 1; t.a", res: "1"}, // #02 + {src: "type T struct {a int}; var t T = T{1}; t.a", res: "1"}, // #03 + {src: "type T struct {a int}; var t *T = &T{1}; t.a", res: "1"}, // #04 }) } @@ -289,5 +291,7 @@ func TestComposite(t *testing.T) { {src: `type T struct {b bool}; m := []T{{true}}; m`, res: `[{true}]`}, // #12 {src: `m := []struct{b bool}{{true}}; m`, res: `[{true}]`}, // #13 {src: `m := map[int]struct{b bool}{1:{true}}; m`, res: `map[1:{true}]`}, // #14 + {src: `type T *struct {b bool}; m := []T{{true}}; m[0]`, res: `&{true}`}, // #15 + {src: `type T *struct {b bool}; m := []T{{true}}; m[0].b`, res: `true`}, // #16 }) } |
