diff --git a/src/core/CompileAssign.go b/src/core/CompileAssign.go index 25b3c0a..85eee9d 100644 --- a/src/core/CompileAssign.go +++ b/src/core/CompileAssign.go @@ -39,6 +39,9 @@ func (f *Function) CompileAssign(node *ast.Assign) error { case *eval.Register: f.Execute(operation, leftValue.Register, right) case *eval.Memory: + // TODO: Reservation needs to be canceled on defer + f.CurrentScope().Reserve(leftValue.Memory.Base) + if operation.Kind == token.Assign { rightValue, err := f.Evaluate(right) diff --git a/tests/programs/struct-lifetime.q b/tests/programs/struct-lifetime.q new file mode 100644 index 0000000..a32f469 --- /dev/null +++ b/tests/programs/struct-lifetime.q @@ -0,0 +1,8 @@ +main() { + c := new(Counter) + c.value += 16 +} + +struct Counter { + value int +} \ No newline at end of file diff --git a/tests/programs_test.go b/tests/programs_test.go index b4b18ed..899cbb7 100644 --- a/tests/programs_test.go +++ b/tests/programs_test.go @@ -69,6 +69,7 @@ var programs = []struct { {"index-static", 0}, {"index-dynamic", 0}, {"struct", 0}, + {"struct-lifetime", 0}, {"len", 0}, {"cast", 0}, {"function-pointer", 0},