minor breaking change: for loop bodies now get their own scope
This commit is contained in:
parent
eee43e4f8f
commit
4e4d466d06
4 changed files with 14 additions and 0 deletions
|
|
@ -41,6 +41,14 @@
|
||||||
what to return if the environment variable does not exist.
|
what to return if the environment variable does not exist.
|
||||||
- Removed PDCurses wrapper from the stdlib and published it as a separate
|
- Removed PDCurses wrapper from the stdlib and published it as a separate
|
||||||
Nimble package.
|
Nimble package.
|
||||||
|
- Bodies of ``for`` loops now get their own scope:
|
||||||
|
|
||||||
|
.. code-block:: nim
|
||||||
|
# now compiles:
|
||||||
|
for i in 0..4:
|
||||||
|
let i = i + 1
|
||||||
|
echo i
|
||||||
|
|
||||||
- The parsing rules of ``if`` expressions were changed so that multiple
|
- The parsing rules of ``if`` expressions were changed so that multiple
|
||||||
statements are allowed in the branches. We found few code examples that
|
statements are allowed in the branches. We found few code examples that
|
||||||
now fail because of this change, but here is one:
|
now fail because of this change, but here is one:
|
||||||
|
|
|
||||||
|
|
@ -335,8 +335,10 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||||
n.sons[L - 2] = semGenericStmt(c, n.sons[L-2], flags, ctx)
|
n.sons[L - 2] = semGenericStmt(c, n.sons[L-2], flags, ctx)
|
||||||
for i in countup(0, L - 3):
|
for i in countup(0, L - 3):
|
||||||
addTempDecl(c, n.sons[i], skForVar)
|
addTempDecl(c, n.sons[i], skForVar)
|
||||||
|
openScope(c)
|
||||||
n.sons[L - 1] = semGenericStmt(c, n.sons[L-1], flags, ctx)
|
n.sons[L - 1] = semGenericStmt(c, n.sons[L-1], flags, ctx)
|
||||||
closeScope(c)
|
closeScope(c)
|
||||||
|
closeScope(c)
|
||||||
of nkBlockStmt, nkBlockExpr, nkBlockType:
|
of nkBlockStmt, nkBlockExpr, nkBlockType:
|
||||||
checkSonsLen(n, 2)
|
checkSonsLen(n, 2)
|
||||||
openScope(c)
|
openScope(c)
|
||||||
|
|
|
||||||
|
|
@ -697,7 +697,9 @@ proc semForVars(c: PContext, n: PNode): PNode =
|
||||||
if sfGenSym notin v.flags and not isDiscardUnderscore(v):
|
if sfGenSym notin v.flags and not isDiscardUnderscore(v):
|
||||||
addForVarDecl(c, v)
|
addForVarDecl(c, v)
|
||||||
inc(c.p.nestedLoopCounter)
|
inc(c.p.nestedLoopCounter)
|
||||||
|
openScope(c)
|
||||||
n.sons[length-1] = semStmt(c, n.sons[length-1])
|
n.sons[length-1] = semStmt(c, n.sons[length-1])
|
||||||
|
closeScope(c)
|
||||||
dec(c.p.nestedLoopCounter)
|
dec(c.p.nestedLoopCounter)
|
||||||
|
|
||||||
proc implicitIterator(c: PContext, it: string, arg: PNode): PNode =
|
proc implicitIterator(c: PContext, it: string, arg: PNode): PNode =
|
||||||
|
|
|
||||||
|
|
@ -366,8 +366,10 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
|
||||||
n.sons[L-2] = semTemplBody(c, n.sons[L-2])
|
n.sons[L-2] = semTemplBody(c, n.sons[L-2])
|
||||||
for i in countup(0, L - 3):
|
for i in countup(0, L - 3):
|
||||||
addLocalDecl(c, n.sons[i], skForVar)
|
addLocalDecl(c, n.sons[i], skForVar)
|
||||||
|
openScope(c)
|
||||||
n.sons[L-1] = semTemplBody(c, n.sons[L-1])
|
n.sons[L-1] = semTemplBody(c, n.sons[L-1])
|
||||||
closeScope(c)
|
closeScope(c)
|
||||||
|
closeScope(c)
|
||||||
of nkBlockStmt, nkBlockExpr, nkBlockType:
|
of nkBlockStmt, nkBlockExpr, nkBlockType:
|
||||||
checkSonsLen(n, 2)
|
checkSonsLen(n, 2)
|
||||||
openScope(c)
|
openScope(c)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue