From 42e0b082144a2c03ef18e0cabc372c90f1753148 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Sat, 14 Apr 2012 13:26:47 +0300 Subject: [PATCH] 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) --- compiler/semstmts.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index d729a691fe..e7051231bc 100755 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -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: