diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 0c6bb26e95..3eb485f8fd 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -592,14 +592,20 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation = else: result = typeRel(c, x, a) # check if it fits of tyTypeDesc: - if a.kind == tyTypeDesc: - if f.sonsLen == 0: - result = isGeneric + var prev = PType(idTableGet(c.bindings, f)) + if prev == nil: + if a.kind == tyTypeDesc: + if f.sonsLen == 0: + result = isGeneric + else: + result = matchTypeClass(c, f, a.sons[0]) + if result == isGeneric: + put(c.bindings, f, a) else: - result = matchTypeClass(c, f, a.sons[0]) - if result == isGeneric: put(c.bindings, f, a) + result = isNone else: - result = isNone + InternalAssert prev.sonsLen == 1 + result = typeRel(c, prev.sons[0], a) of tyExpr, tyStmt: result = isGeneric of tyProxy: diff --git a/tests/reject/tbindtypedesc.nim b/tests/reject/tbindtypedesc.nim new file mode 100644 index 0000000000..d6fbae5374 --- /dev/null +++ b/tests/reject/tbindtypedesc.nim @@ -0,0 +1,12 @@ +discard """ + line: 11 + file: "tbindtypedesc.nim" + errormsg: "type mismatch: got (typedesc[float], string)" +""" + +proc foo(T: typedesc; some: T) = + echo($some) + +foo int, 4 +foo float, "bad" +