bugfix: invalid indentation for 'else' is detected; optional indentation for 'if' expressions
This commit is contained in:
parent
e362cbbfd7
commit
c682a1da2b
4 changed files with 36 additions and 3 deletions
|
|
@ -1024,7 +1024,7 @@ proc getStrOrChar*(a: PNode): string =
|
|||
|
||||
proc isGenericRoutine*(s: PSym): bool =
|
||||
case s.kind
|
||||
of skProc, skTemplate, skMacro, skIterator:
|
||||
of skProc, skTemplate, skMacro, skIterator, skMethod:
|
||||
result = s.ast != nil and s.ast[genericParamsPos].kind != nkEmpty
|
||||
else: nil
|
||||
|
||||
|
|
|
|||
|
|
@ -503,12 +503,15 @@ proc parseIfExpr(p: var TParser): PNode =
|
|||
var branch = newNodeP(nkElifExpr, p)
|
||||
addSon(branch, parseExpr(p))
|
||||
eat(p, tkColon)
|
||||
optInd(p, branch)
|
||||
addSon(branch, parseExpr(p))
|
||||
optInd(p, branch)
|
||||
addSon(result, branch)
|
||||
if p.tok.tokType != tkElif: break
|
||||
var branch = newNodeP(nkElseExpr, p)
|
||||
eat(p, tkElse)
|
||||
eat(p, tkColon)
|
||||
optInd(p, branch)
|
||||
addSon(branch, parseExpr(p))
|
||||
addSon(result, branch)
|
||||
|
||||
|
|
@ -1368,7 +1371,9 @@ proc parseStmt(p: var TParser): PNode =
|
|||
break
|
||||
else:
|
||||
var a = complexOrSimpleStmt(p)
|
||||
if a.kind == nkEmpty: break
|
||||
if a.kind == nkEmpty:
|
||||
parMessage(p, errInvalidIndentation)
|
||||
break
|
||||
addSon(result, a)
|
||||
popInd(p.lex)
|
||||
else:
|
||||
|
|
|
|||
27
tests/reject/tind1.nim
Normal file
27
tests/reject/tind1.nim
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
discard """
|
||||
line: 24
|
||||
errormsg: "invalid indentation"
|
||||
"""
|
||||
|
||||
import macros
|
||||
|
||||
# finally optional indentation in 'if' expressions :-):
|
||||
var x = if 4 != 5:
|
||||
"yes"
|
||||
else:
|
||||
"no"
|
||||
|
||||
macro mymacro(n: expr): expr = result = n[1][0]
|
||||
|
||||
mymacro:
|
||||
echo "test"
|
||||
else:
|
||||
echo "else part"
|
||||
|
||||
|
||||
if 4 == 3:
|
||||
echo "bug"
|
||||
else:
|
||||
echo "no bug"
|
||||
|
||||
|
||||
3
todo.txt
3
todo.txt
|
|
@ -39,13 +39,14 @@ Bugs
|
|||
proc forward[T](x: var T): var T = result = x
|
||||
proc p(): var int =
|
||||
var x: int
|
||||
# reject this call via alias analysis:
|
||||
result = forward(x)
|
||||
|
||||
- bug: stress testing basic method example (eval example)
|
||||
without ``-d:release`` leaks memory; good way to figure out how a
|
||||
fixed amount of stack can hold an arbitrary number of GC roots!
|
||||
- bug: temp2.nim triggers weird compiler and except.nim bug
|
||||
- bug: tsortdev does not run
|
||||
- bug: tsortdev does not run with native GC
|
||||
|
||||
|
||||
version 0.9.XX
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue