diff options
author | Zahary Karadjov <zahary@gmail.com> | 2012-03-25 20:55:21 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2012-03-25 20:55:21 +0300 |
commit | bc2eb0ea9b8a806ddafdb7726c94363fbd2c2f20 (patch) | |
tree | d3a46fd2705e5f58f1d0b93a3d90ef253f642c5d /compiler/sigmatch.nim | |
parent | 296ef07955b9b9813d3dbd0d8de3e483ff79ee08 (diff) | |
download | Nim-bc2eb0ea9b8a806ddafdb7726c94363fbd2c2f20.tar.gz |
generic types can be used like type classes. distinct can be applied to type classes.
Diffstat (limited to 'compiler/sigmatch.nim')
-rwxr-xr-x | compiler/sigmatch.nim | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 74131c21d..767bf3cb8 100755 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -208,9 +208,15 @@ proc tupleRel(mapping: var TIdTable, f, a: PType): TTypeRelation = var y = a.n.sons[i].sym if x.name.id != y.name.id: return isNone -proc constraintRel(mapping: var TIdTable, f, a: PType): TTypeRelation = +proc matchTypeClass(mapping: var TIdTable, f, a: PType): TTypeRelation = result = isNone - if f.kind == a.kind: result = isGeneric + let son = f.sons[0] + if son.kind == a.kind: + result = isGeneric + elif son.kind == tyGenericBody: + if a.kind == tyGenericInst and a.sons[0] == son: + result = isGeneric + put(mapping, f, a) proc procTypeRel(mapping: var TIdTable, f, a: PType): TTypeRelation = proc inconsistentVarTypes(f, a: PType): bool {.inline.} = @@ -261,7 +267,8 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation = assert(a != nil) if a.kind == tyGenericInst and skipTypes(f, {tyVar}).kind notin { - tyGenericBody, tyGenericInvokation, tyGenericParam}: + tyGenericBody, tyGenericInvokation, + tyGenericParam, tyTypeClass }: return typeRel(mapping, f, lastSon(a)) if a.kind == tyVar and f.kind != tyVar: return typeRel(mapping, f, a.sons[0]) @@ -341,7 +348,7 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation = if result < isGeneric: result = isNone else: nil of tyTypeClass: - result = constraintRel(mapping, f.sons[0], a) + result = matchTypeClass(mapping, f, a) of tyOrdinal: if isOrdinalType(a): var x = if a.kind == tyOrdinal: a.sons[0] else: a @@ -414,7 +421,7 @@ proc typeRel(mapping: var TIdTable, f, a: PType): TTypeRelation = of tyGenericBody: let ff = lastSon(f) if ff != nil: result = typeRel(mapping, ff, a) - of tyGenericInvokation: + of tyGenericInvokation: assert(f.sons[0].kind == tyGenericBody) if a.kind == tyGenericInvokation: #InternalError("typeRel: tyGenericInvokation -> tyGenericInvokation") |