Fix bigint + type error

This commit is contained in:
Andrew Morris
2023-03-21 16:47:54 +11:00
parent 660518b083
commit a046a8e4fc
2 changed files with 3 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
// test_output! E: "TypeError: Cannot mix BigInt and other types"
// test_output! E: TypeError{"message":"Cannot mix BigInt and other types"}
export default function () {
return 1 + (1n as unknown as number);

View File

@@ -30,9 +30,7 @@ pub fn op_plus(left: Val, right: Val) -> Result<Val, Val> {
if left_type == VsType::BigInt || right_type == VsType::BigInt {
if left_type != right_type {
return Err(Val::String(Rc::new(
"TypeError: Cannot mix BigInt and other types".to_string(),
)));
return type_error!("Cannot mix BigInt and other types");
}
match (left_prim.as_bigint_data(), right_prim.as_bigint_data()) {
@@ -56,9 +54,7 @@ pub fn op_unary_plus(input: Val) -> Val {
pub fn op_minus(left: Val, right: Val) -> Result<Val, Val> {
match (left.as_bigint_data(), right.as_bigint_data()) {
(Some(left_bigint), Some(right_bigint)) => Ok(Val::BigInt(left_bigint - right_bigint)),
(Some(_), None) | (None, Some(_)) => Err(Val::String(Rc::new(
"TypeError: Cannot mix BigInt with other types".to_string(),
))),
(Some(_), None) | (None, Some(_)) => return type_error!("Cannot mix BigInt with other types"),
_ => Ok(Val::Number(left.to_number() - right.to_number())),
}
}