diff options
author | andri lim <jangko128@gmail.com> | 2018-06-04 22:43:15 +0700 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-06-04 17:43:15 +0200 |
commit | 069a53ad4bff8a3160794360227eceb1fc37d8d8 (patch) | |
tree | 5194be0f4d8afa40b4598d71b64016967908e847 /compiler | |
parent | 05b447374bb6c8d2d09cee46e4f1fd68f5a8067f (diff) | |
download | Nim-069a53ad4bff8a3160794360227eceb1fc37d8d8.tar.gz |
fixes #7906, array and openarray arg vs. ptr/ref generic (#7909)
* fixes #7906, array and openarray arg vs. ptr/ref generic * add comment
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/sem.nim | 6 | ||||
-rw-r--r-- | compiler/types.nim | 4 |
2 files changed, 6 insertions, 4 deletions
diff --git a/compiler/sem.nim b/compiler/sem.nim index 55e1f47dc..d56355f14 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -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) diff --git a/compiler/types.nim b/compiler/types.nim index 7f9b8239f..1fab842cc 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -1043,7 +1043,7 @@ proc inheritanceDiff*(a, b: PType): int = inc(result) result = high(int) -proc commonSuperclass*(a, b: PType, k: TTypeKind): PType = +proc commonSuperclass*(a, b: PType): PType = # quick check: are they the same? if sameObjectTypes(a, b): return a @@ -1063,7 +1063,7 @@ proc commonSuperclass*(a, b: PType, k: TTypeKind): PType = y = skipTypes(y, skipPtrs) if ancestors.contains(y.id): # bug #7818, defer the previous skipTypes - if k in {tyRef, tyPtr}: t = y + if t.kind != tyGenericInst: t = y return t y = y.sons[0] |