diff options
author | Zahary Karadjov <zahary@gmail.com> | 2013-08-23 15:43:27 +0300 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2013-08-23 15:43:27 +0300 |
commit | 56d75bd23ba8e302277614aa5e0ec1ae002fb56d (patch) | |
tree | 63bf7cb90583d370cde738a1a910796304dcd240 /compiler | |
parent | 8682ed9bd0bd8230e779e45cc65c2bfd4661a966 (diff) | |
download | Nim-56d75bd23ba8e302277614aa5e0ec1ae002fb56d.tar.gz |
implemented and documented the new typedesc binding rules
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/semtypes.nim | 12 | ||||
-rw-r--r-- | compiler/sigmatch.nim | 6 |
2 files changed, 13 insertions, 5 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index e5d9058b4..b02fa7c31 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -589,6 +589,8 @@ proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) = else: if sfGenSym notin param.flags: addDecl(c, param) +let typedescId = getIdent"typedesc" + proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode, paramType: PType, paramName: string, info: TLineInfo, anon = false): PType = @@ -636,6 +638,9 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode, result = addImplicitGeneric(c.newTypeWithSons(tyExpr, paramType.sons)) of tyTypeDesc: if tfUnresolved notin paramType.flags: + # naked typedescs are not bindOnce types + if paramType.sonsLen == 0 and paramTypId != nil and + paramTypId.id == typedescId.id: paramTypId = nil result = addImplicitGeneric(c.newTypeWithSons(tyTypeDesc, paramType.sons)) of tyDistinct: if paramType.sonsLen == 1: @@ -762,7 +767,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, r.flags.incl tfRetType result.sons[0] = skipIntLit(r) res.typ = result.sons[0] - + proc semStmtListType(c: PContext, n: PNode, prev: PType): PType = checkMinSonsLen(n, 1) var length = sonsLen(n) @@ -1078,8 +1083,9 @@ proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode = if constraint.kind != nkEmpty: typ = semTypeNode(c, constraint, nil) if typ.kind != tyExpr or typ.len == 0: - if typ.len == 0 and typ.kind == tyTypeDesc: - typ = newTypeS(tyGenericParam, c) + if typ.kind == tyTypeDesc: + if typ.len == 0: + typ = newTypeS(tyTypeDesc, c) else: typ = semGenericConstraints(c, typ) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 4483b1f8b..5766aa164 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -655,7 +655,7 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation = result = typeRel(c, x, a) # check if it fits of tyTypeDesc: var prev = PType(idTableGet(c.bindings, f)) - if prev == nil or true: + if prev == nil: if a.kind == tyTypeDesc: if f.sonsLen == 0: result = isGeneric @@ -667,7 +667,9 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation = result = isNone else: InternalAssert prev.sonsLen == 1 - result = typeRel(c, prev.sons[0], a) + let toMatch = if tfUnresolved in f.flags: a + else: a.sons[0] + result = typeRel(c, prev.sons[0], toMatch) of tyExpr, tyStmt: result = isGeneric of tyProxy: |