fix small bug converting string to int (#6031)

This commit is contained in:
Darren Schroeder 2022-07-12 19:34:26 -05:00 committed by GitHub
parent 8b6232ac87
commit c2f8f4bd9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -291,7 +291,7 @@ fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
}; };
Ok(num) Ok(num)
} }
_ => match a_string.parse::<i64>() { _ => match trimmed.parse::<i64>() {
Ok(n) => Ok(n), Ok(n) => Ok(n),
Err(_) => match a_string.parse::<f64>() { Err(_) => match a_string.parse::<f64>() {
Ok(f) => Ok(f as i64), Ok(f) => Ok(f as i64),
@ -299,7 +299,10 @@ fn int_from_string(a_string: &str, span: Span) -> Result<i64, ShellError> {
"int".to_string(), "int".to_string(),
"string".to_string(), "string".to_string(),
span, span,
None, Some(format!(
r#"string "{}" does not represent a valid integer"#,
trimmed
)),
)), )),
}, },
}, },