clone
Some checks failed
Build / build (push) Failing after 1m45s
Test / build (push) Failing after 12m0s

This commit is contained in:
Chuck Smith
2024-03-15 15:35:45 -04:00
parent 2988719c9c
commit 80f1a2d78c
6 changed files with 59 additions and 6 deletions

View File

@@ -70,7 +70,12 @@ func Eval(node ast.Node, env *object.Environment) object.Object {
if isError(val) {
return val
}
env.Set(node.Name.Value, val)
if mutable, ok := val.(object.Mutable); ok {
env.Set(node.Name.Value, mutable.Clone())
} else {
env.Set(node.Name.Value, val)
}
case *ast.Identifier:
return evalIdentifier(node, env)

View File

@@ -251,6 +251,7 @@ func TestAssignmentStatements(t *testing.T) {
{"let a = 0; a = 5; let b = 0; b = a; b;", 5},
{"let a = 0; a = 5; let b = 0; b = a; let c = 0; c = a + b + 5;", 15},
{"let a = 0; a = 5; let b = 0; b = a; let c = 0; c = a + b + 5; c;", 15},
{"let a = 5; let b = a; a = 0; b;", 5},
}
for _, tt := range tests {
@@ -474,6 +475,7 @@ func TestArrayIndexExpressions(t *testing.T) {
}
for _, tt := range tests {
t.Log(tt.input)
evaluated := testEval(tt.input)
integer, ok := tt.expected.(int)