summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-10-13 01:48:13 +0200
committerAraq <rumpf_a@web.de>2012-10-13 01:48:13 +0200
commit2193460ea6ecd9b2ee3858fffcadd2635f828f9a (patch)
tree33db10f1f1fb6bdbdaeec8f7ed45e531ae99402e /compiler
parent1d307983631b496964d1936a26795fce26da3e39 (diff)
downloadNim-2193460ea6ecd9b2ee3858fffcadd2635f828f9a.tar.gz
bugfix: tests should be green again
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/semexprs.nim7
-rwxr-xr-xcompiler/semstmts.nim11
2 files changed, 13 insertions, 5 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 59089d01c..2c98d9de6 100755
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -723,9 +723,6 @@ proc buildEchoStmt(c: PContext, n: PNode): PNode =
   addSon(result, semExpr(c, arg))
 
 proc discardCheck(result: PNode) =
-  proc ImplicitelyDiscardable(n: PNode): bool {.inline.} =
-    result = isCallExpr(n) and n.sons[0].kind == nkSym and 
-             sfDiscardable in n.sons[0].sym.flags
   if result.typ != nil and result.typ.kind notin {tyStmt, tyEmpty}:
     if result.kind == nkNilLit:
       # XXX too much work and fixing would break bootstrapping:
@@ -1105,7 +1102,9 @@ proc semProcBody(c: PContext, n: PNode): PNode =
     # ``result``:
     if result.kind == nkSym and result.sym == c.p.resultSym:
       nil
-    elif result.kind == nkNilLit:
+    elif result.kind == nkNilLit or ImplicitelyDiscardable(result):
+      # intended semantic: if it's 'discardable' and the context allows for it,
+      # discard it. This is bad for chaining but nicer for C wrappers. 
       # ambiguous :-(
       result.typ = nil
     else:
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 5c0060e20..2d36015a7 100755
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -1088,6 +1088,10 @@ proc insertDestructors(c: PContext, varSection: PNode):
 
       return
 
+proc ImplicitelyDiscardable(n: PNode): bool =
+  result = isCallExpr(n) and n.sons[0].kind == nkSym and 
+           sfDiscardable in n.sons[0].sym.flags
+
 proc semStmtList(c: PContext, n: PNode): PNode =
   # these must be last statements in a block:
   const
@@ -1134,7 +1138,12 @@ proc semStmtList(c: PContext, n: PNode): PNode =
   
   # a statement list (s; e) has the type 'e':
   if result.kind == nkStmtList and result.len > 0:
-    result.typ = lastSon(result).typ
+    var lastStmt = lastSon(result)
+    if not ImplicitelyDiscardable(lastStmt):
+      result.typ = lastStmt.typ
+      #localError(lastStmt.info, errGenerated,
+      #  "Last expression must be explicitly returned if it " &
+      #  "is discardable or discarded")
 
 proc SemStmt(c: PContext, n: PNode): PNode = 
   # now: simply an alias: