Skip to content

Commit b7ad29e

Browse files
authored
fix #18113 (#18124)
1 parent 064fe18 commit b7ad29e

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

compiler/semtempl.nim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,6 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
610610
s.owner.name.s == "vm" and s.name.s == "stackTrace":
611611
incl(s.flags, sfCallsite)
612612

613-
s.ast = n
614-
615613
styleCheckDef(c.config, s)
616614
onDef(n[namePos].info, s)
617615
# check parameter list:
@@ -664,6 +662,12 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
664662
semIdeForTemplateOrGeneric(c, n[bodyPos], ctx.cursorInBody)
665663
closeScope(c)
666664
popOwner(c)
665+
666+
# set the symbol AST after pragmas, at least. This stops pragma that have
667+
# been pushed (implicit) to be explicitly added to the template definition
668+
# and misapplied to the body. see #18113
669+
s.ast = n
670+
667671
if sfCustomPragma in s.flags:
668672
if n[bodyPos].kind != nkEmpty:
669673
localError(c.config, n[bodyPos].info, errImplOfXNotAllowed % s.name.s)

tests/proc/t17157.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
discard """
22
errormsg: "'untyped' is only allowed in templates and macros or magic procs"
3+
disabled: true
34
"""
45

56
template something(op: proc (v: untyped): void): void =

tests/template/t18113.nim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# ensure template pragma handling doesn't eagerly attempt to add an implicit
2+
# 'pushed' pragma to the evaluation of any intermediate AST prior to
3+
# substitution.
4+
5+
# bug #18113
6+
7+
import sequtils
8+
9+
{.push raises: [Defect].}
10+
11+
var a = toSeq([1, 2, 3, 5, 10]).filterIt(it > 5)
12+
13+
doAssert a.len == 1
14+
doAssert a[0] == 10

0 commit comments

Comments
 (0)