fixed mutability
Some checks failed
Build / build (push) Failing after 1m30s
Test / build (push) Failing after 12m1s

This commit is contained in:
Chuck Smith
2024-03-15 15:50:11 -04:00
parent 80f1a2d78c
commit 7463b3af39
7 changed files with 37 additions and 118 deletions

View File

@@ -46,9 +46,9 @@ func Eval(node ast.Node, env *object.Environment) object.Object {
return &object.ReturnValue{Value: val}
case *ast.AssignmentStatement:
ident := evalIdentifier(node.Name, env)
if isError(ident) {
return ident
obj := evalIdentifier(node.Name, env)
if isError(obj) {
return obj
}
val := Eval(node.Value, env)
@@ -56,12 +56,7 @@ func Eval(node ast.Node, env *object.Environment) object.Object {
return val
}
obj, ok := ident.(object.Mutable)
if !ok {
return newError("cannot assign to %s", ident.Type())
}
obj.Set(val)
env.Set(node.Name.Value, val)
return val
@@ -71,8 +66,8 @@ func Eval(node ast.Node, env *object.Environment) object.Object {
return val
}
if mutable, ok := val.(object.Mutable); ok {
env.Set(node.Name.Value, mutable.Clone())
if immutable, ok := val.(object.Immutable); ok {
env.Set(node.Name.Value, immutable.Clone())
} else {
env.Set(node.Name.Value, val)
}