summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semexprs.nim13
-rw-r--r--compiler/semstmts.nim2
-rw-r--r--tests/exprs/tstmtexprs.nim12
3 files changed, 25 insertions, 2 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 55c43ed09..a0f519820 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -780,6 +780,19 @@ proc buildEchoStmt(c: PContext, n: PNode): PNode =
 
 proc semExprNoType(c: PContext, n: PNode): PNode =
   result = semExpr(c, n, {efWantStmt})
+  # make an 'if' expression an 'if' statement again for backwards
+  # compatibility (.discardable was a bad idea!); bug #6980
+  var isStmt = false
+  if result.kind == nkIfExpr:
+    isStmt = true
+    for condActionPair in result:
+      let action = condActionPair.lastSon
+      if not implicitlyDiscardable(action) and not
+          endsInNoReturn(action):
+        isStmt = false
+    if isStmt:
+      result.kind = nkIfStmt
+      result.typ = nil
   discardCheck(c, result)
 
 proc isTypeExpr(n: PNode): bool =
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index b1fa8c19b..dcaa0263b 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -732,7 +732,7 @@ proc semRaise(c: PContext, n: PNode): PNode =
     var typ = n.sons[0].typ
     if typ.kind != tyRef or typ.lastSon.kind != tyObject:
       localError(n.info, errExprCannotBeRaised)
-    
+
     # check if the given object inherits from Exception
     var base = typ.lastSon
     while true:
diff --git a/tests/exprs/tstmtexprs.nim b/tests/exprs/tstmtexprs.nim
index 9283f7268..2a0ec2821 100644
--- a/tests/exprs/tstmtexprs.nim
+++ b/tests/exprs/tstmtexprs.nim
@@ -140,4 +140,14 @@ echo(
   else:
      quo do (a: int) -> bool:
         a mod 3 != 0
-)
\ No newline at end of file
+)
+
+# bug #6980
+
+proc fooBool: bool {.discardable.} =
+  true
+
+if true:
+  fooBool()
+else:
+  raise newException(ValueError, "argh")