From a7fa6d00c1a72f63ce953c3a6131d046aa4e3fee Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Fri, 13 Dec 2024 07:00:53 -0600 Subject: [PATCH] fix 64-bit hex number parsing (#14571) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description Closes #14521 This PR tweaks the way 64-bit hex numbers are parsed. ### Before ```nushell ❯ 0xffffffffffffffef Error: nu::shell::external_command × External command failed ╭─[entry #1:1:1] 1 │ 0xffffffffffffffef · ─────────┬──────── · ╰── Command `0xffffffffffffffef` not found ╰──── help: `0xffffffffffffffef` is neither a Nushell built-in or a known external command ``` ### After ```nushell ❯ 0xffffffffffffffef -17 ``` # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-parser/src/parser.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 07ab35dc36..d71ef77182 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -1532,7 +1532,9 @@ pub fn parse_int(working_set: &mut StateWorkingSet, span: Span) -> Expression { span: Span, radix: u32, ) -> Expression { - if let Ok(num) = i64::from_str_radix(token, radix) { + // Parse as a u64, then cast to i64, otherwise, for numbers like "0xffffffffffffffef", + // you'll get `Error parsing hex string: number too large to fit in target type`. + if let Ok(num) = u64::from_str_radix(token, radix).map(|val| val as i64) { Expression::new(working_set, Expr::Int(num), span, Type::Int) } else { working_set.error(ParseError::InvalidLiteral(