Fixed add overflows

This commit is contained in:
Erin 2021-08-28 23:55:36 +02:00 committed by ondra05
parent 1b243d142c
commit e95e0744c6

View file

@ -272,7 +272,7 @@ impl ops::Add for Value {
match self { match self {
Value::Nul => todo!(), Value::Nul => todo!(),
Value::Str(s) => Value::Str(format!("{}{}", s, rhs.to_string())), Value::Str(s) => Value::Str(format!("{}{}", s, rhs.to_string())),
Value::Int(i) => Value::Int(i + rhs.into_i32()), Value::Int(i) => Value::Int(i.checked_add(rhs.into_i32()).unwrap_or(consts::ANSWER)),
Value::Bool(b) => Value::Bool(b ^ rhs.into_bool()), Value::Bool(b) => Value::Bool(b ^ rhs.into_bool()),
Value::Abool(a) => Value::Abool({ Value::Abool(a) => Value::Abool({
let rhs = rhs.into_abool(); let rhs = rhs.into_abool();