diff options
author | metagn <metagngn@gmail.com> | 2023-12-18 22:38:34 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-18 20:38:34 +0100 |
commit | d3b9711c5e3be9b05fb15c4e39bc7607c606287d (patch) | |
tree | e192543c542552b425f39672797e4b621c6c3e00 | |
parent | 0613537ca0804e61e6fc9ba3fee5ff68408553a0 (diff) | |
download | Nim-d3b9711c5e3be9b05fb15c4e39bc7607c606287d.tar.gz |
retain postfix node in type section typed AST (#23096)
fixes #22933
-rw-r--r-- | compiler/semstmts.nim | 22 | ||||
-rw-r--r-- | testament/important_packages.nim | 3 | ||||
-rw-r--r-- | tests/macros/tastrepr.nim | 5 | ||||
-rw-r--r-- | tests/macros/tgetimpl.nim | 4 |
4 files changed, 29 insertions, 5 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index a0eda36d1..5a0968ba5 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 @@ -1538,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] diff --git a/testament/important_packages.nim b/testament/important_packages.nim index d3d3f0643..d056dac69 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/tastrepr.nim b/tests/macros/tastrepr.nim index c04498a25..668904cae 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 diff --git a/tests/macros/tgetimpl.nim b/tests/macros/tgetimpl.nim index 398957672..e215d2696 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) |