Merge branch 'devel' of github.com:nim-lang/Nim into devel
This commit is contained in:
commit
77d590f483
3 changed files with 20 additions and 11 deletions
|
|
@ -658,7 +658,7 @@ proc pragmaGuard(c: PContext; it: PNode; kind: TSymKind): PSym =
|
||||||
|
|
||||||
proc semCustomPragma(c: PContext, n: PNode): PNode =
|
proc semCustomPragma(c: PContext, n: PNode): PNode =
|
||||||
assert(n.kind in nkPragmaCallKinds + {nkIdent})
|
assert(n.kind in nkPragmaCallKinds + {nkIdent})
|
||||||
|
|
||||||
if n.kind == nkIdent:
|
if n.kind == nkIdent:
|
||||||
result = newTree(nkCall, n)
|
result = newTree(nkCall, n)
|
||||||
elif n.kind == nkExprColonExpr:
|
elif n.kind == nkExprColonExpr:
|
||||||
|
|
@ -667,14 +667,15 @@ proc semCustomPragma(c: PContext, n: PNode): PNode =
|
||||||
else:
|
else:
|
||||||
result = n
|
result = n
|
||||||
|
|
||||||
result = c.semOverloadedCall(c, result, n, {skTemplate}, {})
|
let r = c.semOverloadedCall(c, result, n, {skTemplate}, {})
|
||||||
if sfCustomPragma notin result[0].sym.flags:
|
if r.isNil or sfCustomPragma notin r[0].sym.flags:
|
||||||
invalidPragma(n)
|
invalidPragma(n)
|
||||||
|
else:
|
||||||
if n.kind == nkIdent:
|
result = r
|
||||||
result = result[0]
|
if n.kind == nkIdent:
|
||||||
elif n.kind == nkExprColonExpr:
|
result = result[0]
|
||||||
result.kind = n.kind # pragma(arg) -> pragma: arg
|
elif n.kind == nkExprColonExpr:
|
||||||
|
result.kind = n.kind # pragma(arg) -> pragma: arg
|
||||||
|
|
||||||
proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
|
proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
|
||||||
validPragmas: TSpecialWords): bool =
|
validPragmas: TSpecialWords): bool =
|
||||||
|
|
@ -1016,7 +1017,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
|
||||||
else: sym.flags.incl sfUsed
|
else: sym.flags.incl sfUsed
|
||||||
of wLiftLocals: discard
|
of wLiftLocals: discard
|
||||||
else: invalidPragma(it)
|
else: invalidPragma(it)
|
||||||
else:
|
else:
|
||||||
n.sons[i] = semCustomPragma(c, it)
|
n.sons[i] = semCustomPragma(c, it)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -716,7 +716,7 @@ proc transformExceptBranch(c: PTransf, n: PNode): PTransNode =
|
||||||
result = transformSons(c, n)
|
result = transformSons(c, n)
|
||||||
if n[0].isInfixAs():
|
if n[0].isInfixAs():
|
||||||
let excTypeNode = n[0][1]
|
let excTypeNode = n[0][1]
|
||||||
let actions = newTransNode(nkStmtList, n[1].info, 2)
|
let actions = newTransNode(nkStmtListExpr, n[1], 2)
|
||||||
# Generating `let exc = (excType)(getCurrentException())`
|
# Generating `let exc = (excType)(getCurrentException())`
|
||||||
# -> getCurrentException()
|
# -> getCurrentException()
|
||||||
let excCall = PTransNode(callCodegenProc("getCurrentException", ast.emptyNode))
|
let excCall = PTransNode(callCodegenProc("getCurrentException", ast.emptyNode))
|
||||||
|
|
|
||||||
|
|
@ -21,5 +21,13 @@ proc test2() =
|
||||||
testTemplate(Exception)
|
testTemplate(Exception)
|
||||||
doAssert(not declared(foobar))
|
doAssert(not declared(foobar))
|
||||||
|
|
||||||
|
|
||||||
|
proc testTryAsExpr(i: int) =
|
||||||
|
let x = try: i
|
||||||
|
except ValueError as ex:
|
||||||
|
echo(ex.msg)
|
||||||
|
-1
|
||||||
|
|
||||||
test[Exception]()
|
test[Exception]()
|
||||||
test2()
|
test2()
|
||||||
|
testTryAsExpr(5)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue