From 050bd82404eb2cdba6e7d2e31a540b3e08ab35b7 Mon Sep 17 00:00:00 2001 From: IsaacShelton Date: Thu, 17 Oct 2024 21:35:03 -0500 Subject: [PATCH] Added negative integer/float literals so that coercion works correctly with them --- src/parser/parse_expr/primary/mod.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/parser/parse_expr/primary/mod.rs b/src/parser/parse_expr/primary/mod.rs index c45df786..be741dfe 100644 --- a/src/parser/parse_expr/primary/mod.rs +++ b/src/parser/parse_expr/primary/mod.rs @@ -172,11 +172,23 @@ impl<'a, I: Inflow> Parser<'a, I> { TokenKind::Subtract => { self.input.advance(); - Ok(ExprKind::UnaryOperation(Box::new(UnaryOperation::new_math( - UnaryMathOperator::Negate, - self.parse_expr_primary()?, - ))) - .at(source)) + let mut inside = self.parse_expr_primary()?; + + match &mut inside.kind { + ExprKind::Integer(Integer::Generic(value)) => { + *value = -(&*value); + Ok(inside) + } + ExprKind::Float(value) => { + *value = -*value; + Ok(inside) + } + _ => Ok(ExprKind::UnaryOperation(Box::new(UnaryOperation::new_math( + UnaryMathOperator::Negate, + inside, + ))) + .at(source)), + } } TokenKind::AddressOf => { self.input.advance();