From 438a43d6761f19cb71d1d0928fe76b8734888ee0 Mon Sep 17 00:00:00 2001 From: chloe caruso Date: Sat, 27 Jul 2024 05:11:48 -0700 Subject: [PATCH] fix hex literal warning --- CHANGELOG.md | 1 + src/core/Transform.zig | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a80bd28811771521440c4af557e0907df2af967d..48b498cd5b69e210874be9614955e797343757f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - fix(sema): fix passing structs as function params - fix: diagnostic box drawing characters line up after line 9 - fix: diagnostics on last line of file print correctly +- fix: diagnostics with the leading zero warning ## 0.1.4 diff --git a/src/core/Transform.zig b/src/core/Transform.zig index 1a24a2bd5da49c04ce1fa1798a7fe75d13be8588..0c2a57a99f641bf0d020b2fb6ad6304492193372 100644 --- a/src/core/Transform.zig +++ b/src/core/Transform.zig @@ -881,7 +881,15 @@ fn transformExpression( else => @compileError(unreachable), }; - if (value != 0 and text[0] == '0' and (text.len == 1 or text[1] != '.')) { + const has_zero_prefix = value != 0 and + text[0] == '0' and + (text.len == 1 or switch (tag) { + .number_int => text[1] >= '0' and text[1] < '9', + .number_float => text[1] != '.', + else => @compileError(unreachable), + }); + + if (has_zero_prefix) { try t.report.warn(.zero_prefixed_literal, .{ .token = t.ast.nodeToken(node) }); } -- 2.54.0