Fix bug in built-in string operators.
This commit is contained in:
parent
8f0830af1c
commit
4e5039d4fe
@ -118,6 +118,13 @@ pub fn get_builtin_binary_op_fn(
|
|||||||
$func(x, y)
|
$func(x, y)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
($base:ty => $op:tt) => {
|
||||||
|
return Some(|_, args| {
|
||||||
|
let x = &*args[0].read_lock::<$base>().unwrap();
|
||||||
|
let y = &*args[1].read_lock::<$base>().unwrap();
|
||||||
|
Ok((x $op y).into())
|
||||||
|
})
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_float {
|
macro_rules! impl_float {
|
||||||
@ -327,26 +334,14 @@ pub fn get_builtin_binary_op_fn(
|
|||||||
|
|
||||||
if type1 == TypeId::of::<ImmutableString>() {
|
if type1 == TypeId::of::<ImmutableString>() {
|
||||||
match op {
|
match op {
|
||||||
"+" => {
|
"+" => impl_op!(ImmutableString => +),
|
||||||
return Some(|_, args| {
|
"-" => impl_op!(ImmutableString => -),
|
||||||
let x = &*args[0].read_lock::<ImmutableString>().unwrap();
|
"==" => impl_op!(ImmutableString => ==),
|
||||||
let y = &*args[1].read_lock::<ImmutableString>().unwrap();
|
"!=" => impl_op!(ImmutableString => !=),
|
||||||
Ok((x + y).into())
|
">" => impl_op!(ImmutableString => >),
|
||||||
})
|
">=" => impl_op!(ImmutableString => >=),
|
||||||
}
|
"<" => impl_op!(ImmutableString => <),
|
||||||
"-" => {
|
"<=" => impl_op!(ImmutableString => <=),
|
||||||
return Some(|_, args| {
|
|
||||||
let x = &*args[0].read_lock::<ImmutableString>().unwrap();
|
|
||||||
let y = &*args[1].read_lock::<ImmutableString>().unwrap();
|
|
||||||
Ok((x - y).into())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
"==" => impl_op!(&str => as_str == as_str),
|
|
||||||
"!=" => impl_op!(&str => as_str != as_str),
|
|
||||||
">" => impl_op!(&str => as_str > as_str),
|
|
||||||
">=" => impl_op!(&str => as_str >= as_str),
|
|
||||||
"<" => impl_op!(&str => as_str < as_str),
|
|
||||||
"<=" => impl_op!(&str => as_str <= as_str),
|
|
||||||
_ => return None,
|
_ => return None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user