fixes #7906, array and openarray arg vs. ptr/ref generic (#7909)

* fixes #7906, array and openarray arg vs. ptr/ref generic

* add comment
This commit is contained in:
andri lim 2018-06-04 22:43:15 +07:00 • committed by Andreas Rumpf
commit 069a53ad4b
3 changed files with 120 additions and 31 deletions

View file

@ -158,11 +158,13 @@ proc commonType*(x, y: PType): PType =
a = a.lastSon.skipTypes({tyGenericInst})
b = b.lastSon.skipTypes({tyGenericInst})
if a.kind == tyObject and b.kind == tyObject:
result = commonSuperclass(a, b, k)
result = commonSuperclass(a, b)
# this will trigger an error later:
if result.isNil or result == a: return x
if result == b: return y
if k != tyNone:
# bug #7906, tyRef/tyPtr + tyGenericInst of ref/ptr object ->
# ill-formed AST, no need for additional tyRef/tyPtr
if k != tyNone and x.kind != tyGenericInst:
let r = result
result = newType(k, r.owner)
result.addSonSkipIntLit(r)