summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-01-13 14:59:58 +0100
committerAraq <rumpf_a@web.de>2012-01-13 14:59:58 +0100
commitc682a1da2b4f364718aaa5e895885043a6f7b873 (patch)
tree6053db32966b60ed67584993a201244ee229a8c1
parente362cbbfd79f5b95ad0c7a218a3f7a35d91edbf7 (diff)
downloadNim-c682a1da2b4f364718aaa5e895885043a6f7b873.tar.gz
bugfix: invalid indentation for 'else' is detected; optional indentation for 'if' expressions
-rwxr-xr-xcompiler/ast.nim2
-rwxr-xr-xcompiler/parser.nim7
-rw-r--r--tests/reject/tind1.nim27
-rwxr-xr-xtodo.txt3
4 files changed, 36 insertions, 3 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index b936ec3b4..9e799e051 100755
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -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
 
diff --git a/compiler/parser.nim b/compiler/parser.nim
index acca5feaf..a0d8ad44a 100755
--- a/compiler/parser.nim
+++ b/compiler/parser.nim
@@ -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: 
diff --git a/tests/reject/tind1.nim b/tests/reject/tind1.nim
new file mode 100644
index 000000000..e14de09ce
--- /dev/null
+++ b/tests/reject/tind1.nim
@@ -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"
+
+
diff --git a/todo.txt b/todo.txt
index fc09e5400..ec0c283db 100755
--- a/todo.txt
+++ b/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