type checking and error handling for builtins improved.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user