diff options
author | Zahary Karadjov <zahary@gmail.com> | 2012-04-14 13:26:47 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2012-04-14 13:32:51 +0300 |
commit | 42e0b082144a2c03ef18e0cabc372c90f1753148 (patch) | |
tree | f5812af6b9ab695a74633b3e20509ed4f2d92146 | |
parent | f25c638dc4109445ce1476d6e6f18be034805a0a (diff) | |
download | Nim-42e0b082144a2c03ef18e0cabc372c90f1753148.tar.gz |
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)
-rwxr-xr-x | compiler/semstmts.nim | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index d729a691f..e7051231b 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: |