From 179d82c55bda199b32a108f4ba474f47a83584c9 Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Wed, 13 May 2015 16:53:39 +0200 Subject: [PATCH 1/2] Fix #2662: Don't convert subtype typedesc params There is no point to issue implicit HiddenStdConv encountering subtype of typedesc[Base] parameter on overload resolution, since this will anyway never reach codegen. This change effectively fixes compiler bug for: iterator it(T: typedesc[Base]) = ... for s in it(SubclassOfBase): ... Where HiddenStdConv triggered implicit instantiation of variable of type typedesc[Base] in for transform, that eventually fails at getUniqueType, that refuses to work for typedesc. --- compiler/sigmatch.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 2a9d15b5ae..7ea2c3d6f1 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1281,7 +1281,10 @@ proc paramTypesMatchAux(m: var TCandidate, f, argType: PType, result = implicitConv(nkHiddenStdConv, f, arg, m, c) of isSubtype: inc(m.subtypeMatches) - result = implicitConv(nkHiddenSubConv, f, arg, m, c) + if f.kind == tyTypeDesc: + result = arg + else: + result = implicitConv(nkHiddenSubConv, f, arg, m, c) of isSubrange: inc(m.subtypeMatches) if f.kind == tyVar: From a8fbaf917b854876a01782c644e01ab2e90c5d9f Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Wed, 13 May 2015 19:01:41 +0200 Subject: [PATCH 2/2] Tests for static class proc, methods & iterators This currently covers #2662 & #2710 bugs. --- tests/metatype/ttypedesc3.nim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/metatype/ttypedesc3.nim diff --git a/tests/metatype/ttypedesc3.nim b/tests/metatype/ttypedesc3.nim new file mode 100644 index 0000000000..3d40b25b25 --- /dev/null +++ b/tests/metatype/ttypedesc3.nim @@ -0,0 +1,19 @@ +import typetraits + +type + Base = object of RootObj + Child = object of Base + +proc pr(T: typedesc[Base]) = echo "proc " & T.name +method me(T: typedesc[Base]) = echo "method " & T.name +iterator it(T: typedesc[Base]) = yield "yield " & T.name + +Base.pr +Child.pr + +Base.me +when false: + Child.me #<- bug #2710 + +for s in Base.it: echo s +for s in Child.it: echo s #<- bug #2662