type checking and error handling for builtins improved.
Some checks failed
Build / build (push) Successful in 11m16s
Test / build (push) Failing after 17m0s

This commit is contained in:
Chuck Smith
2024-03-25 16:18:08 -04:00
parent 1c99d2198b
commit 6d234099d1
52 changed files with 650 additions and 433 deletions

View File

@@ -3,13 +3,16 @@ package builtins
import (
"fmt"
"monkey/object"
"monkey/typing"
)
// IdOf ...
func IdOf(args ...object.Object) object.Object {
if len(args) != 1 {
return newError("wrong number of arguments. got=%d, want=1",
len(args))
if err := typing.Check(
"id", args,
typing.ExactArgs(1),
); err != nil {
return newError(err.Error())
}
arg := args[0]
@@ -32,7 +35,7 @@ func IdOf(args ...object.Object) object.Object {
return &object.String{Value: fmt.Sprintf("%p", c)}
} else if b, ok := arg.(*object.Builtin); ok {
return &object.String{Value: fmt.Sprintf("%p", b)}
} else {
return newError("argument 31 to `id()` unsupported got=%T", arg.Type())
}
return nil
}