fixes #1528
This commit is contained in:
parent
31bbc24462
commit
34ab1d3e34
3 changed files with 14 additions and 25 deletions
|
|
@ -1425,7 +1425,7 @@ proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
localError(result.info, "type class predicate failed")
|
localError(result.info, "type class predicate failed")
|
||||||
of tyUnknown: continue
|
of tyUnknown: continue
|
||||||
else: discard
|
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
|
voidContext = true
|
||||||
n.typ = enforceVoidContext
|
n.typ = enforceVoidContext
|
||||||
if i == last and (length == 1 or efWantValue in flags):
|
if i == last and (length == 1 or efWantValue in flags):
|
||||||
|
|
|
||||||
|
|
@ -471,27 +471,6 @@ proc semTemplBodyDirty(c: var TemplCtx, n: PNode): PNode =
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
result.sons[i] = semTemplBodyDirty(c, n.sons[i])
|
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 =
|
proc semTemplateDef(c: PContext, n: PNode): PNode =
|
||||||
var s: PSym
|
var s: PSym
|
||||||
if isTopLevel(c):
|
if isTopLevel(c):
|
||||||
|
|
@ -549,9 +528,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
|
||||||
n.sons[bodyPos] = semTemplBodyDirty(ctx, n.sons[bodyPos])
|
n.sons[bodyPos] = semTemplBodyDirty(ctx, n.sons[bodyPos])
|
||||||
else:
|
else:
|
||||||
n.sons[bodyPos] = semTemplBody(ctx, n.sons[bodyPos])
|
n.sons[bodyPos] = semTemplBody(ctx, n.sons[bodyPos])
|
||||||
if s.typ.sons[0].kind notin {tyStmt, tyTypeDesc}:
|
# only parameters are resolved, no type checking is performed
|
||||||
n.sons[bodyPos] = transformToExpr(n.sons[bodyPos])
|
|
||||||
# only parameters are resolved, no type checking is performed
|
|
||||||
semIdeForTemplateOrGeneric(c, n.sons[bodyPos], ctx.cursorInBody)
|
semIdeForTemplateOrGeneric(c, n.sons[bodyPos], ctx.cursorInBody)
|
||||||
closeScope(c)
|
closeScope(c)
|
||||||
popOwner()
|
popOwner()
|
||||||
|
|
|
||||||
12
tests/discard/tvoidcontext.nim
Normal file
12
tests/discard/tvoidcontext.nim
Normal file
|
|
@ -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"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue