From 0c6f14af048c4bd61c91552af79c003dfd34601e Mon Sep 17 00:00:00 2001 From: chmod222 <304922+chmod222@users.noreply.github.com> Date: Sat, 1 Apr 2023 20:29:28 +0200 Subject: [PATCH] macros: Extend treeTraverse intVal range to nnkUInt64Lit (#21597) * Extend intVal range to nnkUInt64Lit Fixes #21593 * Properly cast intVal as unsigned * Add testcase for #21593 --- lib/core/macros.nim | 2 ++ tests/macros/t21593.nim | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/macros/t21593.nim diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 9cb694bd85..28f52f0a93 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -947,6 +947,8 @@ proc treeTraverse(n: NimNode; res: var string; level = 0; isLisp = false, indent discard # same as nil node in this representation of nnkCharLit .. nnkInt64Lit: res.add(" " & $n.intVal) + of nnkUIntLit .. nnkUInt64Lit: + res.add(" " & $cast[uint64](n.intVal)) of nnkFloatLit .. nnkFloat64Lit: res.add(" " & $n.floatVal) of nnkStrLit .. nnkTripleStrLit, nnkCommentStmt, nnkIdent, nnkSym: diff --git a/tests/macros/t21593.nim b/tests/macros/t21593.nim new file mode 100644 index 0000000000..b0b7ebe757 --- /dev/null +++ b/tests/macros/t21593.nim @@ -0,0 +1,13 @@ +discard """ +nimout: ''' +StmtList + UIntLit 18446744073709551615 + IntLit -1''' +""" + +import macros + +dumpTree: + 0xFFFFFFFF_FFFFFFFF'u + 0xFFFFFFFF_FFFFFFFF +