diff options
author | Araq <rumpf_a@web.de> | 2014-03-05 08:30:05 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-03-05 08:30:05 +0100 |
commit | 4f946cb44e4fe60451b8ce4d15868ef0bce6949a (patch) | |
tree | 2111a867a40015e185b8439ac19b4a22d7b0ee7a | |
parent | 94e444c90fa1c8848b398bc163e7f78d7f0b3080 (diff) | |
download | Nim-4f946cb44e4fe60451b8ce4d15868ef0bce6949a.tar.gz |
fixes #942
-rw-r--r-- | compiler/semstmts.nim | 2 | ||||
-rw-r--r-- | tests/discard/tdiscardable.nim | 16 | ||||
-rw-r--r-- | tests/exprs/texprstmt.nim | 2 |
3 files changed, 18 insertions, 2 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index c8d9e353a..b2b3ceb6d 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1320,7 +1320,7 @@ proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode = if n.sons[i].typ == enforceVoidContext or usesResult(n.sons[i]): voidContext = true n.typ = enforceVoidContext - if i == last and efWantValue in flags: + if i == last and (length == 1 or efWantValue in flags): n.typ = n.sons[i].typ if not isEmptyType(n.typ): n.kind = nkStmtListExpr elif i != last or voidContext or c.inTypeClass > 0: diff --git a/tests/discard/tdiscardable.nim b/tests/discard/tdiscardable.nim index c0551ba2f..a806ccdce 100644 --- a/tests/discard/tdiscardable.nim +++ b/tests/discard/tdiscardable.nim @@ -11,3 +11,19 @@ proc q[T](x, y: T): T {.discardable.} = p(8, 2) q[float](0.8, 0.2) +# bug #942 + +template maybeMod(x: Tinteger, module:Natural):expr = + if module > 0: x mod module + else: x + +proc foo(b: int):int = + var x = 1 + result = x.maybeMod(b) # Works fine + +proc bar(b: int):int = + result = 1 + result = result.maybeMod(b) # Error: value returned by statement has to be discarded + +echo foo(0) +echo bar(0) diff --git a/tests/exprs/texprstmt.nim b/tests/exprs/texprstmt.nim index b32394d8d..355da2407 100644 --- a/tests/exprs/texprstmt.nim +++ b/tests/exprs/texprstmt.nim @@ -1,6 +1,6 @@ discard """ line: 10 - errormsg: "value returned by statement has to be discarded" + errormsg: "value of type 'string' has to be discarded" """ # bug #578 |