diff --git a/compiler/nir/ast2ir.nim b/compiler/nir/ast2ir.nim index 907d45013ee8a..d82f17429324f 100644 --- a/compiler/nir/ast2ir.nim +++ b/compiler/nir/ast2ir.nim @@ -2165,6 +2165,7 @@ proc genVarSection(c: var ProcCon; n: PNode) = else: var vn = a[0] if vn.kind == nkPragmaExpr: vn = vn[0] + if vn.kind == nkPostfix: vn = vn[1] if vn.kind == nkSym: let s = vn.sym if s.kind == skConst: diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 5a0968ba55cb5..6020486bb6caf 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -780,12 +780,22 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode = if importantComments(c.config): # keep documentation information: b.comment = a.comment - # postfix not generated here (to generate, get rid of it in transf) if a[j].kind == nkPragmaExpr: - var p = newNodeI(nkPragmaExpr, a.info) - p.add newSymNode(v) + var p = newNodeI(nkPragmaExpr, a[j].info) + if a[j][0].kind == nkPostfix: + var pf = newNodeI(nkPostfix, a[j][0].info) + pf.add a[j][0][0] + pf.add newSymNode(v) + p.add pf + else: + p.add newSymNode(v) p.add a[j][1] b.add p + elif a[j].kind == nkPostfix: + var pf = newNodeI(nkPostfix, a[j].info) + pf.add a[j][0] + pf.add newSymNode(v) + b.add pf else: b.add newSymNode(v) # keep type desc for doc generator @@ -891,12 +901,22 @@ proc semConst(c: PContext, n: PNode): PNode = setVarType(c, v, typ) b = newNodeI(nkConstDef, a.info) if importantComments(c.config): b.comment = a.comment - # postfix not generated here (to generate, get rid of it in transf) if a[j].kind == nkPragmaExpr: - var p = newNodeI(nkPragmaExpr, a.info) - p.add newSymNode(v) + var p = newNodeI(nkPragmaExpr, a[j].info) + if a[j][0].kind == nkPostfix: + var pf = newNodeI(nkPostfix, a[j][0].info) + pf.add a[j][0][0] + pf.add newSymNode(v) + p.add pf + else: + p.add newSymNode(v) p.add a[j][1].copyTree b.add p + elif a[j].kind == nkPostfix: + var pf = newNodeI(nkPostfix, a[j].info) + pf.add a[j][0] + pf.add newSymNode(v) + b.add pf else: b.add newSymNode(v) b.add a[1] @@ -2201,7 +2221,10 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, # name isn't changed (see taccent_highlight). We don't want to check if this is the # defintion yet since we are missing some info (comments, side effects) s = semIdentDef(c, n[namePos], kind, reportToNimsuggest=isHighlight) - n[namePos] = newSymNode(s) + if n[namePos].kind == nkPostfix: + n[namePos][1] = newSymNode(s) + else: + n[namePos] = newSymNode(s) when false: # disable for now if sfNoForward in c.module.flags and diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index e572efdc0bec0..2ef090519a2ed 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -644,7 +644,10 @@ proc semTemplateDef(c: PContext, n: PNode): PNode = incl(s.flags, sfNoalias) pushOwner(c, s) openScope(c) - n[namePos] = newSymNode(s) + if n[namePos].kind == nkPostfix: + n[namePos][1] = newSymNode(s) + else: + n[namePos] = newSymNode(s) pragmaCallable(c, s, n, templatePragmas) implicitPragmas(c, s, n.info, templatePragmas) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index fe87c29731ade..6b5f33c87be9e 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -858,6 +858,16 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int, fSym.sym.ast.flags.incl nfSkipFieldChecking if a.kind == nkEmpty: father.add fSym else: a.add fSym + if n[i].kind == nkPragmaExpr: + if n[i][0].kind == nkPostfix: + n[i][0][1] = fSym + else: + n[i][0] = fSym + else: + if n[i].kind == nkPostfix: + n[i][1] = fSym + else: + n[i] = fSym styleCheckDef(c, f) onDef(f.info, f) if a.kind != nkEmpty: father.add a diff --git a/compiler/transf.nim b/compiler/transf.nim index edae6b847df8a..9a5702b6e3c0f 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -191,6 +191,7 @@ proc transformVarSection(c: PTransf, v: PNode): PNode = elif it.kind == nkIdentDefs: var vn = it[0] if vn.kind == nkPragmaExpr: vn = vn[0] + if vn.kind == nkPostfix: vn = vn[1] if vn.kind == nkSym: internalAssert(c.graph.config, it.len == 3) let x = freshVar(c, vn.sym) @@ -327,8 +328,10 @@ proc introduceNewLocalVars(c: PTransf, n: PNode): PNode = return n of nkProcDef: # todo optimize nosideeffects? result = newTransNode(n) - let x = newSymNode(copySym(n[namePos].sym, c.idgen)) - idNodeTablePut(c.transCon.mapping, n[namePos].sym, x) + var name = n[namePos] + if name.kind == nkPostfix: name = name[1] + let x = newSymNode(copySym(name.sym, c.idgen)) + idNodeTablePut(c.transCon.mapping, name.sym, x) result[namePos] = x # we have to copy proc definitions for iters for i in 1..