From 08ccc6e7b306e4d721e45510766dc26a45554664 Mon Sep 17 00:00:00 2001 From: metagn <10591326+metagn@users.noreply.github.com> Date: Mon, 18 Dec 2023 20:55:37 +0300 Subject: [PATCH 1/3] retain postfix node in type section typed AST fixes #22933 --- compiler/semstmts.nim | 13 +++++++++++-- tests/macros/tastrepr.nim | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index a0eda36d1eada..81d80f1c90213 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1259,6 +1259,9 @@ proc typeSectionTypeName(c: PContext; n: PNode): PNode = result = n[0] else: result = n + if result.kind == nkPostfix: + if result.len != 2: illFormedAst(n, c.config) + result = result[1] if result.kind != nkSym: illFormedAst(n, c.config) proc typeDefLeftSidePass(c: PContext, typeSection: PNode, i: int) = @@ -1326,9 +1329,15 @@ proc typeDefLeftSidePass(c: PContext, typeSection: PNode, i: int) = elif s.owner == nil: s.owner = getCurrOwner(c) if name.kind == nkPragmaExpr: - typeDef[0][0] = newSymNode(s) + if name[0].kind == nkPostfix: + typeDef[0][0][1] = newSymNode(s) + else: + typeDef[0][0] = newSymNode(s) else: - typeDef[0] = newSymNode(s) + if name.kind == nkPostfix: + typeDef[0][1] = newSymNode(s) + else: + typeDef[0] = newSymNode(s) proc typeSectionLeftSidePass(c: PContext, n: PNode) = # process the symbols on the left side for the whole type section, before diff --git a/tests/macros/tastrepr.nim b/tests/macros/tastrepr.nim index c04498a25b37e..668904caec226 100644 --- a/tests/macros/tastrepr.nim +++ b/tests/macros/tastrepr.nim @@ -11,6 +11,8 @@ for i, (x, y) in pairs(data): var a = 1 b = 2 +type + A* = object var data = @[(1, "one"), (2, "two")] for (i, d) in pairs(data): @@ -20,6 +22,8 @@ for i, d in pairs(data): for i, (x, y) in pairs(data): discard var (a, b) = (1, 2) +type + A* = object ''' """ @@ -44,3 +48,4 @@ echoTypedAndUntypedRepr: for i, (x,y) in pairs(data): discard var (a,b) = (1,2) + type A* = object # issue #22933 From b2b6f9952d407f99280400054a7b706432d571d3 Mon Sep 17 00:00:00 2001 From: metagn <10591326+metagn@users.noreply.github.com> Date: Mon, 18 Dec 2023 21:01:04 +0300 Subject: [PATCH 2/3] hopefully this doesn't drag out too long --- compiler/semstmts.nim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 81d80f1c90213..5a0968ba55cb5 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1547,8 +1547,15 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) = of nkSym: obj.ast[0] = symNode of nkPragmaExpr: obj.ast[0] = a[0].shallowCopy - obj.ast[0][0] = symNode + if a[0][0].kind == nkPostfix: + obj.ast[0][0] = a[0][0].shallowCopy + obj.ast[0][0][1] = symNode + else: + obj.ast[0][0] = symNode obj.ast[0][1] = a[0][1] + of nkPostfix: + obj.ast[0] = a[0].shallowCopy + obj.ast[0][1] = symNode else: assert(false) obj.ast[1] = a[1] obj.ast[2] = a[2][0] From 39ab56b1f34ed98dec4216e96a6bc41566491505 Mon Sep 17 00:00:00 2001 From: metagn <10591326+metagn@users.noreply.github.com> Date: Mon, 18 Dec 2023 22:05:09 +0300 Subject: [PATCH 3/3] fix nim CI, disable NESM, wait for unchained [skip ci] --- testament/important_packages.nim | 3 ++- tests/macros/tgetimpl.nim | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/testament/important_packages.nim b/testament/important_packages.nim index d3d3f06437881..d056dac69db9f 100644 --- a/testament/important_packages.nim +++ b/testament/important_packages.nim @@ -97,7 +97,8 @@ pkg "memo" pkg "msgpack4nim", "nim c -r tests/test_spec.nim" pkg "nake", "nim c nakefile.nim" pkg "neo", "nim c -d:blas=openblas --mm:refc tests/all.nim", url = "https://github.com/nim-lang/neo" -pkg "nesm", "nimble tests", "https://github.com/nim-lang/NESM", useHead = true +pkg "nesm", "nimble tests", "https://github.com/nim-lang/NESM", useHead = true, allowFailure = true + # inactive, tests not adapted to #23096 pkg "netty" pkg "nico", allowFailure = true pkg "nicy", "nim c -r src/nicy.nim" diff --git a/tests/macros/tgetimpl.nim b/tests/macros/tgetimpl.nim index 3989576729b62..e215d26968497 100644 --- a/tests/macros/tgetimpl.nim +++ b/tests/macros/tgetimpl.nim @@ -75,7 +75,9 @@ assert: check_gen_proc(len(a)) == (false, true) macro check(x: type): untyped = let z = getType(x) let y = getImpl(z[1]) - let sym = if y[0].kind == nnkSym: y[0] else: y[0][0] + var sym = y[0] + if sym.kind == nnkPragmaExpr: sym = sym[0] + if sym.kind == nnkPostfix: sym = sym[1] expectKind(z[1], nnkSym) expectKind(sym, nnkSym) expectKind(y[2], nnkObjectTy)