From 272cb5d31242a6fedefef246907eac2ca7eb56c1 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 22 Sep 2025 09:28:28 +0200 Subject: [PATCH] Fixed incorrect struct load offset --- src/core/evaluateRight.go | 7 +------ src/core/{structFieldMemory.go => structField.go} | 0 tests/array-string.q | 9 +++++++++ tests/tests_test.go | 1 + 4 files changed, 11 insertions(+), 6 deletions(-) rename src/core/{structFieldMemory.go => structField.go} (100%) create mode 100644 tests/array-string.q diff --git a/src/core/evaluateRight.go b/src/core/evaluateRight.go index 87cdc1d..9109f04 100644 --- a/src/core/evaluateRight.go +++ b/src/core/evaluateRight.go @@ -26,12 +26,7 @@ func (f *Function) evaluateRight(expr *expression.Expression) (ssa.Value, error) fields := make([]ssa.Value, 0, len(typ.Fields)) for _, field := range typ.Fields { - fieldMemory := &ssa.Memory{ - Address: memory.Address, - Index: f.Append(&ssa.Int{Int: int(field.Offset)}), - Scale: false, - Typ: field.Type, - } + fieldMemory := f.structField(memory, field) fieldValue := f.Append(&ssa.Load{ Memory: fieldMemory, diff --git a/src/core/structFieldMemory.go b/src/core/structField.go similarity index 100% rename from src/core/structFieldMemory.go rename to src/core/structField.go diff --git a/tests/array-string.q b/tests/array-string.q new file mode 100644 index 0000000..f67f511 --- /dev/null +++ b/tests/array-string.q @@ -0,0 +1,9 @@ +import io + +main() { + s := new(string, 2) + s[0] = "Hello" + s[1] = "World" + io.write(s[0]) + io.write(s[1]) +} \ No newline at end of file diff --git a/tests/tests_test.go b/tests/tests_test.go index 80baeb4..481dfdf 100644 --- a/tests/tests_test.go +++ b/tests/tests_test.go @@ -111,6 +111,7 @@ var tests = []run{ {"array-struct", "", "", 0}, {"array-struct-copy", "", "", 0}, {"array-struct-copy-call", "", "", 0}, + {"array-string", "", "HelloWorld", 0}, {"pointer-to-pointer", "", "", 0}, } -- 2.51.2