WIP: as with generics.
This commit is contained in:
parent
814f527175
commit
656da1f6a9
5 changed files with 21 additions and 10 deletions
|
|
@ -434,3 +434,6 @@ proc pickSym*(c: PContext, n: PNode; kind: TSymKind;
|
||||||
if a.kind == kind and flags <= a.flags:
|
if a.kind == kind and flags <= a.flags:
|
||||||
return a
|
return a
|
||||||
a = nextOverloadIter(o, c, n)
|
a = nextOverloadIter(o, c, n)
|
||||||
|
|
||||||
|
proc isExceptAs*(n: PNode): bool =
|
||||||
|
return n.kind == nkInfix and considerQuotedIdent(n[0]).s == "as"
|
||||||
|
|
@ -339,8 +339,17 @@ proc semGenericStmt(c: PContext, n: PNode,
|
||||||
checkMinSonsLen(a, 1)
|
checkMinSonsLen(a, 1)
|
||||||
var L = sonsLen(a)
|
var L = sonsLen(a)
|
||||||
for j in countup(0, L-2):
|
for j in countup(0, L-2):
|
||||||
|
debug(a.sons[j])
|
||||||
|
if a.sons[j].isExceptAs():
|
||||||
|
openScope(c)
|
||||||
|
addTempDecl(c, getIdentNode(a.sons[j][2]), skLet)
|
||||||
|
a.sons[j] = semGenericStmt(c, a.sons[j][1], flags+{withinTypeDesc}, ctx)
|
||||||
|
closeScope(c)
|
||||||
|
else:
|
||||||
a.sons[j] = semGenericStmt(c, a.sons[j], flags+{withinTypeDesc}, ctx)
|
a.sons[j] = semGenericStmt(c, a.sons[j], flags+{withinTypeDesc}, ctx)
|
||||||
|
debug(a)
|
||||||
a.sons[L-1] = semGenericStmtScope(c, a.sons[L-1], flags, ctx)
|
a.sons[L-1] = semGenericStmtScope(c, a.sons[L-1], flags, ctx)
|
||||||
|
|
||||||
of nkVarSection, nkLetSection:
|
of nkVarSection, nkLetSection:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
var a = n.sons[i]
|
var a = n.sons[i]
|
||||||
|
|
|
||||||
|
|
@ -286,8 +286,7 @@ proc semTry(c: PContext, n: PNode): PNode =
|
||||||
var typeNode = a.sons[j] # e.g. `Exception`
|
var typeNode = a.sons[j] # e.g. `Exception`
|
||||||
var symbolNode: PNode = nil # e.g. `foobar`
|
var symbolNode: PNode = nil # e.g. `foobar`
|
||||||
# Handle the case where the `Exception as foobar` syntax is used.
|
# Handle the case where the `Exception as foobar` syntax is used.
|
||||||
if typeNode.kind == nkInfix and
|
if typeNode.isExceptAs():
|
||||||
considerQuotedIdent(typeNode[0]).s == "as":
|
|
||||||
typeNode = a.sons[j].sons[1]
|
typeNode = a.sons[j].sons[1]
|
||||||
symbolNode = a.sons[j].sons[2]
|
symbolNode = a.sons[j].sons[2]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -703,7 +703,7 @@ proc transformCall(c: PTransf, n: PNode): PTransNode =
|
||||||
|
|
||||||
proc transformExceptBranch(c: PTransf, n: PNode): PTransNode =
|
proc transformExceptBranch(c: PTransf, n: PNode): PTransNode =
|
||||||
result = transformSons(c, n)
|
result = transformSons(c, n)
|
||||||
if n[0].kind == nkInfix and considerQuotedIdent(n[0][0]).s == "as":
|
if n[0].isExceptAs():
|
||||||
let excTypeNode = n[0][1]
|
let excTypeNode = n[0][1]
|
||||||
let actions = newTransNode(nkStmtList, n[1].info, 2)
|
let actions = newTransNode(nkStmtList, n[1].info, 2)
|
||||||
# Generating `let exc = (excType)(getCurrentException())`
|
# Generating `let exc = (excType)(getCurrentException())`
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''Hello'''
|
output: '''Hello'''
|
||||||
"""
|
"""
|
||||||
|
proc test[T]() =
|
||||||
try:
|
try:
|
||||||
raise newException(Exception, "Hello")
|
raise newException(T, "Hello")
|
||||||
except Exception as foobar:
|
except T as foobar:
|
||||||
echo(foobar.msg)
|
echo(foobar.msg)
|
||||||
|
|
||||||
|
test[Exception]()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue