From b50c453b140b29b24d340d7b0aa61791bfca405d Mon Sep 17 00:00:00 2001 From: demotomohiro Date: Wed, 29 Oct 2025 18:26:45 +0900 Subject: [PATCH] adds procedure test code and fix bugs --- compiler/icnif/nifdecoder.nim | 6 ++++-- compiler/icnif/nifencoder.nim | 3 ++- tests/icnif/tencode_node2node.nim | 1 + tests/icnif/testcode/modtestprocs.nim | 9 +++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 tests/icnif/testcode/modtestprocs.nim diff --git a/compiler/icnif/nifdecoder.nim b/compiler/icnif/nifdecoder.nim index 77cbff5517..08ac204064 100644 --- a/compiler/icnif/nifdecoder.nim +++ b/compiler/icnif/nifdecoder.nim @@ -261,7 +261,9 @@ proc fromNif(c: var DecodeContext; n: var Cursor): PNode = case kind: of nkEmpty: result = newNodeI(nkEmpty, c.fromNifLineInfo(n)) - inc n + incExpect n, {Ident, DotToken} + let flags = fromNifNodeFlags n + result.flags = flags skipParRi n of nkIdent: incExpect n, Ident @@ -304,7 +306,7 @@ proc fromNif(c: var DecodeContext; n: var Cursor): PNode = else: c.withNode n, result, kind: while n.kind != ParRi: - result.add c.fromNif n + result.addAllowNil c.fromNif n else: assert false, "Not yet implemented " & $n.kind diff --git a/compiler/icnif/nifencoder.nim b/compiler/icnif/nifencoder.nim index 0f7b6720f4..0903144c80 100644 --- a/compiler/icnif/nifencoder.nim +++ b/compiler/icnif/nifencoder.nim @@ -143,6 +143,7 @@ proc toNif(c: var EncodeContext; n: PNode) = of nkEmpty: let info = c.toNif n.info c.dest.addParLe pool.tags.getOrIncl(toNifTag(nkEmpty)), info + c.dest.writeNodeFlags(n.flags) c.dest.addParRi of nkIdent: let info = c.toNif n.info @@ -187,7 +188,7 @@ proc toNif(c: var EncodeContext; n: PNode) = c.withNode n: discard else: - assert n.len > 0, $n.kind + assert n.kind in {nkArgList, nkBracket} or n.len > 0, $n.kind c.withNode(n): for i in 0 ..< n.len: c.toNif n[i] diff --git a/tests/icnif/tencode_node2node.nim b/tests/icnif/tencode_node2node.nim index c71f53c63c..923057c426 100644 --- a/tests/icnif/tencode_node2node.nim +++ b/tests/icnif/tencode_node2node.nim @@ -330,3 +330,4 @@ testNifEncDec(graph, "modtest1.nim") testNifEncDec(graph, "modtestliterals.nim") testNifEncDec(graph, "modtesttypesections.nim") testNifEncDec(graph, "modtestpragmas.nim") +testNifEncDec(graph, "modtestprocs.nim") diff --git a/tests/icnif/testcode/modtestprocs.nim b/tests/icnif/testcode/modtestprocs.nim new file mode 100644 index 0000000000..6f2f0eab00 --- /dev/null +++ b/tests/icnif/testcode/modtestprocs.nim @@ -0,0 +1,9 @@ +proc foo() = discard +proc bar(x: int): int = x +proc baz(x, y: int): string = $(x + y) + +proc baz(a: bool; b: string; c: int): float = + if a and b == "" and c == 0: + result = 0.0 + else: + result = 1.0