type checking and error handling for builtins improved.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package builtins
|
||||
|
||||
import "monkey/object"
|
||||
import (
|
||||
"monkey/object"
|
||||
"monkey/typing"
|
||||
)
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -9,17 +12,12 @@ import (
|
||||
|
||||
// Assert ...
|
||||
func Assert(args ...object.Object) object.Object {
|
||||
if len(args) != 2 {
|
||||
return newError("wrong number of arguments. got=%d, want=2",
|
||||
len(args))
|
||||
}
|
||||
if args[0].Type() != object.BOOLEAN_OBJ {
|
||||
return newError("argument #1 to `assert` must be BOOLEAN, got %s",
|
||||
args[0].Type())
|
||||
}
|
||||
if args[1].Type() != object.STRING_OBJ {
|
||||
return newError("argument #2 to `assert` must be STRING, got %s",
|
||||
args[0].Type())
|
||||
if err := typing.Check(
|
||||
"assert", args,
|
||||
typing.ExactArgs(2),
|
||||
typing.WithTypes(object.BOOLEAN_OBJ, object.STRING_OBJ),
|
||||
); err != nil {
|
||||
return newError(err.Error())
|
||||
}
|
||||
|
||||
if !args[0].(*object.Boolean).Value {
|
||||
|
||||
Reference in New Issue
Block a user