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:
Zahary Karadjov
2012-04-14 13:26:47 +03:00
parent f25c638dc4
commit 42e0b08214

View File

@@ -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: