mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
Distinguish between malformed ints and floats
This commit is contained in:
parent
9b3bb7abd7
commit
9f39153a35
3 changed files with 8 additions and 7 deletions
|
@ -58,7 +58,8 @@ pub enum Expr<'a> {
|
||||||
|
|
||||||
// Runtime errors
|
// Runtime errors
|
||||||
MalformedStr(Box<[Loc<Problem>]>),
|
MalformedStr(Box<[Loc<Problem>]>),
|
||||||
MalformedNumber(Problem),
|
MalformedInt(Problem),
|
||||||
|
MalformedFloat(Problem),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
|
|
@ -111,12 +111,12 @@ where
|
||||||
|
|
||||||
match f64_buf.parse::<f64>() {
|
match f64_buf.parse::<f64>() {
|
||||||
Ok(float) if float.is_finite() => Expr::Float(float),
|
Ok(float) if float.is_finite() => Expr::Float(float),
|
||||||
_ => Expr::MalformedNumber(Problem::OutsideSupportedRange),
|
_ => Expr::MalformedFloat(Problem::OutsideSupportedRange),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match before_decimal.parse::<i64>() {
|
match before_decimal.parse::<i64>() {
|
||||||
Ok(int_val) => Expr::Int(int_val),
|
Ok(int_val) => Expr::Int(int_val),
|
||||||
Err(_) => Expr::MalformedNumber(Problem::OutsideSupportedRange),
|
Err(_) => Expr::MalformedInt(Problem::OutsideSupportedRange),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -317,7 +317,7 @@ mod test_parser {
|
||||||
fn int_too_large() {
|
fn int_too_large() {
|
||||||
assert_parses_to(
|
assert_parses_to(
|
||||||
(i64::MAX as i128 + 1).to_string().as_str(),
|
(i64::MAX as i128 + 1).to_string().as_str(),
|
||||||
MalformedNumber(Problem::OutsideSupportedRange),
|
MalformedInt(Problem::OutsideSupportedRange),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,7 +325,7 @@ mod test_parser {
|
||||||
fn int_too_small() {
|
fn int_too_small() {
|
||||||
assert_parses_to(
|
assert_parses_to(
|
||||||
(i64::MIN as i128 - 1).to_string().as_str(),
|
(i64::MIN as i128 - 1).to_string().as_str(),
|
||||||
MalformedNumber(Problem::OutsideSupportedRange),
|
MalformedInt(Problem::OutsideSupportedRange),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,7 +371,7 @@ mod test_parser {
|
||||||
fn float_too_large() {
|
fn float_too_large() {
|
||||||
assert_parses_to(
|
assert_parses_to(
|
||||||
format!("{}1.0", f64::MAX).as_str(),
|
format!("{}1.0", f64::MAX).as_str(),
|
||||||
MalformedNumber(Problem::OutsideSupportedRange),
|
MalformedFloat(Problem::OutsideSupportedRange),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +379,7 @@ mod test_parser {
|
||||||
fn float_too_small() {
|
fn float_too_small() {
|
||||||
assert_parses_to(
|
assert_parses_to(
|
||||||
format!("{}1.0", f64::MIN).as_str(),
|
format!("{}1.0", f64::MIN).as_str(),
|
||||||
MalformedNumber(Problem::OutsideSupportedRange),
|
MalformedFloat(Problem::OutsideSupportedRange),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue