remove standalone 'except' and 'finally' statements that have been deprecated for years

This commit is contained in:
Andreas Rumpf 2018-04-28 00:00:19 +02:00
commit f755808350

View file

@ -1843,40 +1843,6 @@ proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode =
# nkNilLit, nkEmpty}: # nkNilLit, nkEmpty}:
# dec last # dec last
for i in countup(0, length - 1): for i in countup(0, length - 1):
let k = n.sons[i].kind
case k
of nkFinally, nkExceptBranch:
# stand-alone finally and except blocks are
# transformed into regular try blocks:
#
# var f = fopen("somefile") | var f = fopen("somefile")
# finally: fclose(f) | try:
# ... | ...
# | finally:
# | fclose(f)
var deferPart: PNode
if k == nkDefer:
deferPart = newNodeI(nkFinally, n.sons[i].info)
deferPart.add n.sons[i].sons[0]
elif k == nkFinally:
message(n.info, warnDeprecated,
"use 'defer'; standalone 'finally'")
deferPart = n.sons[i]
else:
message(n.info, warnDeprecated,
"use an explicit 'try'; standalone 'except'")
deferPart = n.sons[i]
var tryStmt = newNodeI(nkTryStmt, n.sons[i].info)
var body = newNodeI(nkStmtList, n.sons[i].info)
if i < n.sonsLen - 1:
body.sons = n.sons[(i+1)..n.len-1]
tryStmt.addSon(body)
tryStmt.addSon(deferPart)
n.sons[i] = semTry(c, tryStmt)
n.sons.setLen(i+1)
n.typ = n.sons[i].typ
return
else:
var expr = semExpr(c, n.sons[i], flags) var expr = semExpr(c, n.sons[i], flags)
n.sons[i] = expr n.sons[i] = expr
if c.matchedConcept != nil and expr.typ != nil and if c.matchedConcept != nil and expr.typ != nil and