fixes #18863 [backport] (#18871)

This commit is contained in:
Andreas Rumpf 2021-09-20 11:37:54 +02:00 • committed by GitHub
commit 14ced06bb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View file

@ -1905,7 +1905,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
if tfTriggersCompileTime in s.typ.flags: incl(s.flags, sfCompileTime) if tfTriggersCompileTime in s.typ.flags: incl(s.flags, sfCompileTime)
if n[patternPos].kind != nkEmpty: if n[patternPos].kind != nkEmpty:
n[patternPos] = semPattern(c, n[patternPos]) n[patternPos] = semPattern(c, n[patternPos], s)
if s.kind == skIterator: if s.kind == skIterator:
s.typ.flags.incl(tfIterator) s.typ.flags.incl(tfIterator)
elif s.kind == skFunc: elif s.kind == skFunc:

View file

@ -334,7 +334,7 @@ proc semTemplSomeDecl(c: var TemplCtx, n: PNode, symKind: TSymKind; start = 0) =
illFormedAst(a, c.c.config) illFormedAst(a, c.c.config)
proc semPattern(c: PContext, n: PNode): PNode proc semPattern(c: PContext, n: PNode; s: PSym): PNode
proc semTemplBodySons(c: var TemplCtx, n: PNode): PNode = proc semTemplBodySons(c: var TemplCtx, n: PNode): PNode =
result = n result = n
@ -645,7 +645,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
if allUntyped: incl(s.flags, sfAllUntyped) if allUntyped: incl(s.flags, sfAllUntyped)
if n[patternPos].kind != nkEmpty: if n[patternPos].kind != nkEmpty:
n[patternPos] = semPattern(c, n[patternPos]) n[patternPos] = semPattern(c, n[patternPos], s)
var ctx: TemplCtx var ctx: TemplCtx
ctx.toBind = initIntSet() ctx.toBind = initIntSet()
@ -798,7 +798,7 @@ proc semPatternBody(c: var TemplCtx, n: PNode): PNode =
for i in 0..<n.len: for i in 0..<n.len:
result[i] = semPatternBody(c, n[i]) result[i] = semPatternBody(c, n[i])
proc semPattern(c: PContext, n: PNode): PNode = proc semPattern(c: PContext, n: PNode; s: PSym): PNode =
openScope(c) openScope(c)
var ctx: TemplCtx var ctx: TemplCtx
ctx.toBind = initIntSet() ctx.toBind = initIntSet()
@ -813,3 +813,4 @@ proc semPattern(c: PContext, n: PNode): PNode =
elif result.len == 0: elif result.len == 0:
localError(c.config, n.info, "a pattern cannot be empty") localError(c.config, n.info, "a pattern cannot be empty")
closeScope(c) closeScope(c)
addPattern(c, LazySym(sym: s))