From 42bdd90226c38450ef29a086d89df5718f7a32da Mon Sep 17 00:00:00 2001 From: Evan Haas Date: Mon, 26 Feb 2024 14:58:15 -0800 Subject: [PATCH] Parser: make unary minus work with float values --- src/aro/Parser.zig | 2 +- test/cases/float values.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 test/cases/float values.c diff --git a/src/aro/Parser.zig b/src/aro/Parser.zig index 39f15b8a..7276d177 100644 --- a/src/aro/Parser.zig +++ b/src/aro/Parser.zig @@ -6934,7 +6934,7 @@ fn unExpr(p: *Parser) Error!Result { try p.errStr(.invalid_argument_un, tok, try p.typeStr(operand.ty)); try operand.usualUnaryConversion(p, tok); - if (operand.val.is(.int, p.comp)) { + if (operand.val.is(.int, p.comp) or operand.val.is(.float, p.comp)) { _ = try operand.val.sub(Value.zero, operand.val, operand.ty, p.comp); } else { operand.val = .{}; diff --git a/test/cases/float values.c b/test/cases/float values.c new file mode 100644 index 00000000..3d16702c --- /dev/null +++ b/test/cases/float values.c @@ -0,0 +1,2 @@ +_Static_assert(-1.0 - 1.0 == -2.0, ""); +_Static_assert(-2.0f == -2.0, "");