further steps to eliminate generics bugs

This commit is contained in:
Araq 2012-01-11 08:52:50 +01:00
commit 92e1a21b26
4 changed files with 28 additions and 15 deletions

View file

@ -54,9 +54,10 @@ proc initCandidate*(c: var TCandidate, callee: PType) =
proc put(t: var TIdTable, key, val: PType) {.inline.} = proc put(t: var TIdTable, key, val: PType) {.inline.} =
IdTablePut(t, key, val) IdTablePut(t, key, val)
if val.kind == tyObject and isDefined"testme" and when false:
IdentEq(val.sym.name, "TTable"): if val.kind == tyObject and isDefined"testme" and
assert false IdentEq(val.sym.name, "TTable"):
assert false
proc initCandidate*(c: var TCandidate, callee: PSym, binding: PNode) = proc initCandidate*(c: var TCandidate, callee: PSym, binding: PNode) =
initCandidateAux(c, callee.typ) initCandidateAux(c, callee.typ)
@ -120,6 +121,7 @@ proc getNotFoundError*(c: PContext, n: PNode): string =
if sym.kind in {skProc, skMethod, skIterator, skConverter}: if sym.kind in {skProc, skMethod, skIterator, skConverter}:
add(candidates, getProcHeader(sym)) add(candidates, getProcHeader(sym))
add(candidates, "\n") add(candidates, "\n")
#debug(sym.typ)
sym = nextOverloadIter(o, c, n.sons[0]) sym = nextOverloadIter(o, c, n.sons[0])
if candidates != "": if candidates != "":
add(result, "\n" & msgKindToString(errButExpected) & "\n" & candidates) add(result, "\n" & msgKindToString(errButExpected) & "\n" & candidates)
@ -169,7 +171,12 @@ proc handleFloatRange(f, a: PType): TTypeRelation =
proc isObjectSubtype(a, f: PType): bool = proc isObjectSubtype(a, f: PType): bool =
var t = a var t = a
while t != nil and not sameObjectTypes(f, t): t = t.sons[0] assert t.kind == tyObject
while t != nil and not sameObjectTypes(f, t):
assert t.kind == tyObject
t = t.sons[0]
if t == nil: break
t = skipTypes(t, {tyGenericInst})
result = t != nil result = t != nil
proc minRel(a, b: TTypeRelation): TTypeRelation = proc minRel(a, b: TTypeRelation): TTypeRelation =
@ -402,15 +409,15 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation =
#InternalError("typeRel: tyGenericInvokation -> tyGenericInvokation") #InternalError("typeRel: tyGenericInvokation -> tyGenericInvokation")
# simply no match for now: # simply no match for now:
nil nil
elif a.kind == tyGenericInst: elif a.kind == tyGenericInst and
if (f.sons[0].containerID == a.sons[0].containerID) and (f.sons[0].containerID == a.sons[0].containerID) and
(sonsLen(a) - 1 == sonsLen(f)): (sonsLen(a) - 1 == sonsLen(f)):
assert(a.sons[0].kind == tyGenericBody) assert(a.sons[0].kind == tyGenericBody)
for i in countup(1, sonsLen(f) - 1): for i in countup(1, sonsLen(f) - 1):
if a.sons[i].kind == tyGenericParam: if a.sons[i].kind == tyGenericParam:
InternalError("wrong instantiated type!") InternalError("wrong instantiated type!")
if typeRel(mapping, f.sons[i], a.sons[i]) < isGeneric: return if typeRel(mapping, f.sons[i], a.sons[i]) <= isSubtype: return
result = isGeneric result = isGeneric
else: else:
result = typeRel(mapping, f.sons[0], a) result = typeRel(mapping, f.sons[0], a)
if result != isNone: if result != isNone:

View file

@ -1,5 +1,5 @@
discard """ discard """
disabled: true disabled: false
""" """
## ##
@ -12,4 +12,6 @@ type
TGen[T] = object TGen[T] = object
TSpef = TGen[string] TSpef = TGen[string]
var
s: TSpef

View file

@ -1,5 +1,5 @@
discard """ discard """
disabled: true disabled: false
""" """
type type

View file

@ -1,8 +1,12 @@
version 0.8.14 version 0.8.14
============== ==============
- fix memory corruption bug triggered by visual c++ in release mode - fix memory corruption bug triggered by visual c++ in release mode:
* sysasserts in incref
* force full collection in ccgstmts.nim
- fix line info in assertions - fix line info in assertions
- fix remaining generics bugs
version 0.9.0 version 0.9.0
============= =============