diff --git a/compiler/ast.nim b/compiler/ast.nim index 155113d8a7..4ea68dc996 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1598,7 +1598,7 @@ proc toObject*(typ: PType): PType = ## Otherwise ``typ`` is simply returned as-is. result = typ if result.kind == tyRef: - result = result.sons[0] + result = result.lastSon when false: proc containsNil*(n: PNode): bool = diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index f428b47080..35c686bcba 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -286,7 +286,8 @@ proc semTry(c: PContext, n: PNode): PNode = var typeNode = a.sons[j] # e.g. `Exception` var symbolNode: PNode = nil # e.g. `foobar` # Handle the case where the `Exception as foobar` syntax is used. - if typeNode.kind == nkInfix: + if typeNode.kind == nkInfix and + considerQuotedIdent(typeNode[0]).s == "as": typeNode = a.sons[j].sons[1] symbolNode = a.sons[j].sons[2] diff --git a/compiler/transf.nim b/compiler/transf.nim index 3a4e25eb56..8944ff43b2 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -21,7 +21,7 @@ import intsets, strutils, lists, options, ast, astalgo, trees, treetab, msgs, os, idents, renderer, types, passes, semfold, magicsys, cgmeth, rodread, - lambdalifting, sempass2, lowerings + lambdalifting, sempass2, lowerings, lookups # implementation @@ -703,7 +703,7 @@ proc transformCall(c: PTransf, n: PNode): PTransNode = proc transformExceptBranch(c: PTransf, n: PNode): PTransNode = result = transformSons(c, n) - if n[0].kind == nkInfix: + if n[0].kind == nkInfix and considerQuotedIdent(n[0][0]).s == "as": let excTypeNode = n[0][1] let actions = newTransNode(nkStmtList, n[1].info, 2) # Generating `let exc = (excType)(getCurrentException())`