summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/sigmatch.nim5
-rw-r--r--tests/metatype/ttypedesc3.nim19
2 files changed, 23 insertions, 1 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 2a9d15b5a..7ea2c3d6f 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:
diff --git a/tests/metatype/ttypedesc3.nim b/tests/metatype/ttypedesc3.nim
new file mode 100644
index 000000000..3d40b25b2
--- /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