diff --git a/src/wren_core.c b/src/wren_core.c index 673fa014..174fcd51 100644 --- a/src/wren_core.c +++ b/src/wren_core.c @@ -436,35 +436,30 @@ DEF_NATIVE(num_divide) DEF_NATIVE(num_mod) { if (!validateNum(vm, args, 1, "Right operand")) return PRIM_ERROR; - if (!IS_NUM(args[1])) RETURN_NULL; RETURN_NUM(fmod(AS_NUM(args[0]), AS_NUM(args[1]))); } DEF_NATIVE(num_lt) { - // TODO: Error on wrong argument type. - if (!IS_NUM(args[1])) RETURN_NULL; + if (!validateNum(vm, args, 1, "Right operand")) return PRIM_ERROR; RETURN_BOOL(AS_NUM(args[0]) < AS_NUM(args[1])); } DEF_NATIVE(num_gt) { - // TODO: Error on wrong argument type. - if (!IS_NUM(args[1])) RETURN_NULL; + if (!validateNum(vm, args, 1, "Right operand")) return PRIM_ERROR; RETURN_BOOL(AS_NUM(args[0]) > AS_NUM(args[1])); } DEF_NATIVE(num_lte) { - // TODO: Error on wrong argument type. - if (!IS_NUM(args[1])) RETURN_NULL; + if (!validateNum(vm, args, 1, "Right operand")) return PRIM_ERROR; RETURN_BOOL(AS_NUM(args[0]) <= AS_NUM(args[1])); } DEF_NATIVE(num_gte) { - // TODO: Error on wrong argument type. - if (!IS_NUM(args[1])) RETURN_NULL; + if (!validateNum(vm, args, 1, "Right operand")) return PRIM_ERROR; RETURN_BOOL(AS_NUM(args[0]) >= AS_NUM(args[1])); } diff --git a/test/number/greater_than_equal_operand_not_num.wren b/test/number/greater_than_equal_operand_not_num.wren new file mode 100644 index 00000000..b4c452c9 --- /dev/null +++ b/test/number/greater_than_equal_operand_not_num.wren @@ -0,0 +1 @@ +1 >= false // expect runtime error: Right operand must be a number. diff --git a/test/number/greater_than_operand_not_num.wren b/test/number/greater_than_operand_not_num.wren new file mode 100644 index 00000000..839e7f62 --- /dev/null +++ b/test/number/greater_than_operand_not_num.wren @@ -0,0 +1 @@ +1 > false // expect runtime error: Right operand must be a number. diff --git a/test/number/less_than_equal_operand_not_num.wren b/test/number/less_than_equal_operand_not_num.wren new file mode 100644 index 00000000..0a126819 --- /dev/null +++ b/test/number/less_than_equal_operand_not_num.wren @@ -0,0 +1 @@ +1 <= false // expect runtime error: Right operand must be a number. diff --git a/test/number/less_than_operand_not_num.wren b/test/number/less_than_operand_not_num.wren new file mode 100644 index 00000000..33fd4aac --- /dev/null +++ b/test/number/less_than_operand_not_num.wren @@ -0,0 +1 @@ +1 < false // expect runtime error: Right operand must be a number.