diff options
author | Araq <rumpf_a@web.de> | 2015-09-10 13:20:15 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-09-10 13:20:15 +0200 |
commit | 34ab1d3e340635620d41ea1b0250830971648dda (patch) | |
tree | 9de5954635cbbcb62c4a9fe0706100d43f180cfd | |
parent | 31bbc24462e1c5e05c2eea4837292ac5e9367515 (diff) | |
download | Nim-34ab1d3e340635620d41ea1b0250830971648dda.tar.gz |
fixes #1528
-rw-r--r-- | compiler/semstmts.nim | 2 | ||||
-rw-r--r-- | compiler/semtempl.nim | 25 | ||||
-rw-r--r-- | tests/discard/tvoidcontext.nim | 12 |
3 files changed, 14 insertions, 25 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index ffda6a1bb..4399c0ab0 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1425,7 +1425,7 @@ proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode = localError(result.info, "type class predicate failed") of tyUnknown: continue else: discard - if n.sons[i].typ == enforceVoidContext or usesResult(n.sons[i]): + if n.sons[i].typ == enforceVoidContext: #or usesResult(n.sons[i]): voidContext = true n.typ = enforceVoidContext if i == last and (length == 1 or efWantValue in flags): diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 4d1eae48f..84ba49e0c 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -471,27 +471,6 @@ proc semTemplBodyDirty(c: var TemplCtx, n: PNode): PNode = for i in countup(0, sonsLen(n) - 1): result.sons[i] = semTemplBodyDirty(c, n.sons[i]) -proc transformToExpr(n: PNode): PNode = - var realStmt: int - result = n - case n.kind - of nkStmtList: - realStmt = - 1 - for i in countup(0, sonsLen(n) - 1): - case n.sons[i].kind - of nkCommentStmt, nkEmpty, nkNilLit: - discard - else: - if realStmt == - 1: realStmt = i - else: realStmt = - 2 - if realStmt >= 0: result = transformToExpr(n.sons[realStmt]) - else: n.kind = nkStmtListExpr - of nkBlockStmt: - n.kind = nkBlockExpr - #nkIfStmt: n.kind = nkIfExpr // this is not correct! - else: - discard - proc semTemplateDef(c: PContext, n: PNode): PNode = var s: PSym if isTopLevel(c): @@ -549,9 +528,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode = n.sons[bodyPos] = semTemplBodyDirty(ctx, n.sons[bodyPos]) else: n.sons[bodyPos] = semTemplBody(ctx, n.sons[bodyPos]) - if s.typ.sons[0].kind notin {tyStmt, tyTypeDesc}: - n.sons[bodyPos] = transformToExpr(n.sons[bodyPos]) - # only parameters are resolved, no type checking is performed + # only parameters are resolved, no type checking is performed semIdeForTemplateOrGeneric(c, n.sons[bodyPos], ctx.cursorInBody) closeScope(c) popOwner() diff --git a/tests/discard/tvoidcontext.nim b/tests/discard/tvoidcontext.nim new file mode 100644 index 000000000..c3ea68bae --- /dev/null +++ b/tests/discard/tvoidcontext.nim @@ -0,0 +1,12 @@ +discard """ + errormsg: "value of type 'string' has to be discarded" + line: 12 +""" + +proc valid*(): string = + let x = 317 + "valid" + +proc invalid*(): string = + result = "foo" + "invalid" |