Skip to content

Commit

Permalink
small try
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Feb 21, 2022
1 parent 1b656b7 commit 013a793
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ proc semTry(c: PContext, n: PNode; flags: TExprFlags): PNode =
localError(c.config, typeNode.info, errExceptionAlreadyHandled)
typeNode = newNodeIT(nkType, typeNode.info, typ)
isImported
template semExceptBranchType2(typeNode: PNode, node: PNode): bool =
# returns true if exception type is imported type
let typ = semTypeNode(c, typeNode, nil).toObject()
var isImported = false
if isImportedException(typ, c.config):
isImported = true
elif not isException(typ):
localError(c.config, typeNode.info, errExprCannotBeRaised)

if containsOrIncl(check, typ.id):
localError(c.config, typeNode.info, errExceptionAlreadyHandled)
node.add newNodeIT(nkType, typeNode.info, typ)
isImported

result = n
checkMinSonsLen(n, 2, c.config)
Expand Down Expand Up @@ -238,14 +251,16 @@ proc semTry(c: PContext, n: PNode; flags: TExprFlags): PNode =
# cannot be followed by a ``except KeyError, ... : body`` block
inc catchAllExcepts
var isNative, isImported: bool
var m = newNode(a.kind)
for j in 0..<a.len-1:
let tmp = semExceptBranchType(a[j])
let tmp = semExceptBranchType2(a[j], m)
if tmp: isImported = true
else: isNative = true

if isNative and isImported:
localError(c.config, a[0].info, "Mix of imported and native exception types is not allowed in one except branch")

n[i] = m
elif a.kind == nkFinally:
if i != n.len-1:
localError(c.config, a.info, "Only one finally is allowed after all other branches")
Expand Down

0 comments on commit 013a793

Please sign in to comment.