Merge branch 'Fixes-7845' of https://github.com/cooldome/Nim into cooldome-Fixes-7845

This commit is contained in:
Araq 2018-10-15 11:50:12 +02:00
commit bf01d7136e
3 changed files with 23 additions and 8 deletions

View file

@ -1714,8 +1714,7 @@ proc toVar*(typ: PType): PType =
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
if typ.kind == tyObject:
if typ.skipTypes({tyAlias, tyGenericInst}).kind == tyObject:
result = newType(tyRef, typ.owner)
rawAddSon(result, typ)
@ -1723,15 +1722,15 @@ 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
if result.kind == tyRef:
result = result.lastSon
let t = typ.skipTypes({tyAlias, tyGenericInst})
if t.kind == tyRef: t.lastSon
else: typ
proc isException*(t: PType): bool =
# check if `y` is object type and it inherits from Exception
assert(t != nil)
if t.kind != tyObject:
if t.kind notin {tyObject, tyGenericInst}:
return false
var base = t