mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-04 04:02:41 +00:00
fix the usage of definedInScope in pegs.=~
template `=~`*(s: string, pattern: TPeg): bool =
when not definedInScope(matches):
var matches: array[0..maxSubpatterns-1, string]
It seems that this never worked as intended.
I discovered it now, because when variables' names are preserved, multiple
variables named `matches` were created. The reason this happens is that
when the template is used as an if condition, the if scope is already entered,
but the variables end up in the outer scope.
This patch is consistent with how `expr` templates work, but makes the
definition of a variable injection template like := a bit harder, yet still possible.
(note that if foo := bar(): is still not creating properly scoped variable prior to the patch)
This commit is contained in:
@@ -50,8 +50,8 @@ proc semIf(c: PContext, n: PNode): PNode =
|
||||
case it.kind
|
||||
of nkElifBranch:
|
||||
checkSonsLen(it, 2)
|
||||
openScope(c.tab)
|
||||
it.sons[0] = forceBool(c, semExprWithType(c, it.sons[0]))
|
||||
openScope(c.tab)
|
||||
it.sons[1] = semStmt(c, it.sons[1])
|
||||
closeScope(c.tab)
|
||||
of nkElse:
|
||||
|
||||
Reference in New Issue
Block a user