From 92e1a21b260996538465a1c32a09943f001adc34 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 11 Jan 2012 08:52:50 +0100 Subject: [PATCH] further steps to eliminate generics bugs --- compiler/sigmatch.nim | 31 ++++++++++++------- .../tcan_alias_specialised_generic.nim | 4 ++- tests/compile/tgenericmatcher.nim | 2 +- todo.txt | 6 +++- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 6b6ebb40a..04278ba87 100755 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -54,9 +54,10 @@ proc initCandidate*(c: var TCandidate, callee: PType) = proc put(t: var TIdTable, key, val: PType) {.inline.} = IdTablePut(t, key, val) - if val.kind == tyObject and isDefined"testme" and - IdentEq(val.sym.name, "TTable"): - assert false + when false: + if val.kind == tyObject and isDefined"testme" and + IdentEq(val.sym.name, "TTable"): + assert false proc initCandidate*(c: var TCandidate, callee: PSym, binding: PNode) = initCandidateAux(c, callee.typ) @@ -120,6 +121,7 @@ proc getNotFoundError*(c: PContext, n: PNode): string = if sym.kind in {skProc, skMethod, skIterator, skConverter}: add(candidates, getProcHeader(sym)) add(candidates, "\n") + #debug(sym.typ) sym = nextOverloadIter(o, c, n.sons[0]) if candidates != "": add(result, "\n" & msgKindToString(errButExpected) & "\n" & candidates) @@ -169,7 +171,12 @@ proc handleFloatRange(f, a: PType): TTypeRelation = proc isObjectSubtype(a, f: PType): bool = 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 proc minRel(a, b: TTypeRelation): TTypeRelation = @@ -402,15 +409,15 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation = #InternalError("typeRel: tyGenericInvokation -> tyGenericInvokation") # simply no match for now: nil - elif a.kind == tyGenericInst: - if (f.sons[0].containerID == a.sons[0].containerID) and + elif a.kind == tyGenericInst and + (f.sons[0].containerID == a.sons[0].containerID) and (sonsLen(a) - 1 == sonsLen(f)): - assert(a.sons[0].kind == tyGenericBody) - for i in countup(1, sonsLen(f) - 1): - if a.sons[i].kind == tyGenericParam: - InternalError("wrong instantiated type!") - if typeRel(mapping, f.sons[i], a.sons[i]) < isGeneric: return - result = isGeneric + assert(a.sons[0].kind == tyGenericBody) + for i in countup(1, sonsLen(f) - 1): + if a.sons[i].kind == tyGenericParam: + InternalError("wrong instantiated type!") + if typeRel(mapping, f.sons[i], a.sons[i]) <= isSubtype: return + result = isGeneric else: result = typeRel(mapping, f.sons[0], a) if result != isNone: diff --git a/tests/compile/tcan_alias_specialised_generic.nim b/tests/compile/tcan_alias_specialised_generic.nim index a8f1972c8..8d4a29abd 100755 --- a/tests/compile/tcan_alias_specialised_generic.nim +++ b/tests/compile/tcan_alias_specialised_generic.nim @@ -1,5 +1,5 @@ discard """ - disabled: true + disabled: false """ ## @@ -12,4 +12,6 @@ type TGen[T] = object TSpef = TGen[string] +var + s: TSpef diff --git a/tests/compile/tgenericmatcher.nim b/tests/compile/tgenericmatcher.nim index 6ff0dd505..edd0c4cf1 100755 --- a/tests/compile/tgenericmatcher.nim +++ b/tests/compile/tgenericmatcher.nim @@ -1,5 +1,5 @@ discard """ - disabled: true + disabled: false """ type diff --git a/todo.txt b/todo.txt index 97ee5ebd5..a932bfd0c 100755 --- a/todo.txt +++ b/todo.txt @@ -1,8 +1,12 @@ 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 remaining generics bugs + version 0.9.0 =============