diff options
author | cooldome <ariabushenko@bk.ru> | 2018-06-10 22:49:09 +0100 |
---|---|---|
committer | cooldome <ariabushenko@bk.ru> | 2018-06-10 22:49:09 +0100 |
commit | 7302a8ce7a0cc566c098b29fdb73c5da3b8e6ac0 (patch) | |
tree | 071c466a780b598876525f3799b5e5a9e3fdd7d2 /compiler | |
parent | 03653ab61e6eed6811c5df0677a2bf2aa722ef9c (diff) | |
download | Nim-7302a8ce7a0cc566c098b29fdb73c5da3b8e6ac0.tar.gz |
Fixes 7845
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ast.nim | 12 | ||||
-rw-r--r-- | compiler/semstmts.nim | 5 |
2 files changed, 8 insertions, 9 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 5a84b2b02..dd84452f9 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1667,7 +1667,7 @@ proc skipStmtList*(n: PNode): PNode = proc toRef*(typ: PType): PType = ## If ``typ`` is a tyObject then it is converted into a `ref <typ>` and ## returned. Otherwise ``typ`` is simply returned as-is. - result = typ + let typ = typ.skipTypes({tyAlias, tyGenericInst}) if typ.kind == tyObject: result = newType(tyRef, typ.owner) rawAddSon(result, typ) @@ -1676,7 +1676,7 @@ proc toObject*(typ: PType): PType = ## If ``typ`` is a tyRef then its immediate son is returned (which in many ## cases should be a ``tyObject``). ## Otherwise ``typ`` is simply returned as-is. - result = typ + result = typ.skipTypes({tyAlias, tyGenericInst}) if result.kind == tyRef: result = result.lastSon @@ -1684,14 +1684,12 @@ proc isException*(t: PType): bool = # check if `y` is object type and it inherits from Exception assert(t != nil) - if t.kind != tyObject: - return false - var base = t - while base != nil: + while base != nil and base.kind in {tyObject, tyRef, tyGenericInst, tyAlias}: if base.sym != nil and base.sym.magic == mException: return true - base = base.lastSon + if base.len == 0: break + else: base = base.lastSon return false proc isImportedException*(t: PType; conf: ConfigRef): bool = diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 7213601de..12337262a 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -755,9 +755,10 @@ proc semRaise(c: PContext, n: PNode): PNode = checkSonsLen(n, 1, c.config) if n[0].kind != nkEmpty: n[0] = semExprWithType(c, n[0]) - let typ = n[0].typ + var typ = n[0].typ if not isImportedException(typ, c.config): - if typ.kind != tyRef or typ.lastSon.kind != tyObject: + typ = typ.skipTypes({tyAlias, tyGenericInst}) + if typ.kind != tyRef: localError(c.config, n.info, errExprCannotBeRaised) if not isException(typ.lastSon): localError(c.config, n.info, "raised object of type $1 does not inherit from Exception", |