This commit is contained in:
Andreas Rumpf 2016-08-10 11:14:02 +02:00
commit 57b8664a0c
2 changed files with 13 additions and 6 deletions

View file

@ -985,11 +985,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
of tyGenericBody: of tyGenericBody:
considerPreviousT: considerPreviousT:
let ff = lastSon(f) if a.kind == tyGenericInst and a.sons[0] == f:
var depth = 0
if a.kind == tyGenericInst and (a.sons[0] == f): #or (ff != nil and ff.kind == tyObject and isGenericSubtype(a.sons[0], ff, depth))):
c.inheritancePenalty += depth
bindingRet isGeneric bindingRet isGeneric
let ff = lastSon(f)
if ff != nil: if ff != nil:
result = typeRel(c, ff, a) result = typeRel(c, ff, a)
@ -1006,7 +1004,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
for i in countup(1, sonsLen(f) - 1): for i in countup(1, sonsLen(f) - 1):
if x.sons[i].kind == tyGenericParam: if x.sons[i].kind == tyGenericParam:
internalError("wrong instantiated type!") internalError("wrong instantiated type!")
elif typeRel(c, f.sons[i], x.sons[i]) <= isSubtype: return elif typeRel(c, f.sons[i], x.sons[i]) <= isSubtype:
# Workaround for regression #4589
if f.sons[i].kind != tyTypeDesc: return
c.inheritancePenalty += depth c.inheritancePenalty += depth
result = isGeneric result = isGeneric
else: else:
@ -1024,7 +1024,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
# #
# we steal the generic parameters from the tyGenericBody: # we steal the generic parameters from the tyGenericBody:
for i in countup(1, sonsLen(f) - 1): for i in countup(1, sonsLen(f) - 1):
var x = PType(idTableGet(c.bindings, genericBody.sons[i-1])) let x = PType(idTableGet(c.bindings, genericBody.sons[i-1]))
if x == nil: if x == nil:
discard "maybe fine (for eg. a==tyNil)" discard "maybe fine (for eg. a==tyNil)"
elif x.kind in {tyGenericInvocation, tyGenericParam}: elif x.kind in {tyGenericInvocation, tyGenericParam}:

View file

@ -0,0 +1,7 @@
# bug #4589
import tables
type SimpleTable*[TKey, TVal] = TableRef[TKey, TVal]
template newSimpleTable*(TKey, TVal: typedesc): SimpleTable[TKey, TVal] = newTable[TKey, TVal]()
var fontCache : SimpleTable[string, SimpleTable[int32, int]]
fontCache = newSimpleTable(string, SimpleTable[int32, int])