mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
Validate number comparison operand types.
This commit is contained in:
@ -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]));
|
||||
}
|
||||
|
||||
|
||||
1
test/number/greater_than_equal_operand_not_num.wren
Normal file
1
test/number/greater_than_equal_operand_not_num.wren
Normal file
@ -0,0 +1 @@
|
||||
1 >= false // expect runtime error: Right operand must be a number.
|
||||
1
test/number/greater_than_operand_not_num.wren
Normal file
1
test/number/greater_than_operand_not_num.wren
Normal file
@ -0,0 +1 @@
|
||||
1 > false // expect runtime error: Right operand must be a number.
|
||||
1
test/number/less_than_equal_operand_not_num.wren
Normal file
1
test/number/less_than_equal_operand_not_num.wren
Normal file
@ -0,0 +1 @@
|
||||
1 <= false // expect runtime error: Right operand must be a number.
|
||||
1
test/number/less_than_operand_not_num.wren
Normal file
1
test/number/less_than_operand_not_num.wren
Normal file
@ -0,0 +1 @@
|
||||
1 < false // expect runtime error: Right operand must be a number.
|
||||
Reference in New Issue
Block a user