From ecbe39abac284fb5b9e583913f8fd000106b5cb3 Mon Sep 17 00:00:00 2001 From: Michael Schimmel Date: Tue, 30 Sep 2025 17:50:34 +0200 Subject: [PATCH] Fixed closure upvalue scoping --- Src/AST/Myc.Ast.Scope.pas | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Src/AST/Myc.Ast.Scope.pas b/Src/AST/Myc.Ast.Scope.pas index 1f263a9..64b5a14 100644 --- a/Src/AST/Myc.Ast.Scope.pas +++ b/Src/AST/Myc.Ast.Scope.pas @@ -281,18 +281,13 @@ begin end; procedure TExecutionScope.DefineBoxed(const Address: TResolvedAddress; const Value: TDataValue); -var - targetScope: TExecutionScope; - i: Integer; begin // This method is only for local variables (ScopeDepth=0). Assert(Address.ScopeDepth = 0, 'DefineBoxed can only be used on the current scope.'); - targetScope := Self; + Assert((Address.SlotIndex >= 0) and (Address.SlotIndex < Length(FValues)), 'Invalid slot index during DefineBoxed.'); - Assert((Address.SlotIndex >= 0) and (Address.SlotIndex < Length(targetScope.FValues)), 'Invalid slot index during DefineBoxed.'); - - targetScope.FValues[Address.SlotIndex].Value := TDataValue.FromIntf(TValueCell.Create(Value)); - targetScope.FValues[Address.SlotIndex].IsBoxed := True; + FValues[Address.SlotIndex].Value := TDataValue.FromIntf(TValueCell.Create(Value)); + FValues[Address.SlotIndex].IsBoxed := True; end; procedure TExecutionScope.DumpScope(const ABuilder: TStringBuilder; AIndent: Integer);