summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2015-05-13 19:24:27 +0200
committerAndreas Rumpf <rumpf_a@web.de>2015-05-13 19:24:27 +0200
commitf293e2c152db01291c6a94e3df790af7da1c85fc (patch)
tree8167c4cc1854b9d2c894e2cec97f337697a62bf8
parent0bf78e262950aeaa97bf3b64e88728a5681fd2e5 (diff)
parenta8fbaf917b854876a01782c644e01ab2e90c5d9f (diff)
downloadNim-f293e2c152db01291c6a94e3df790af7da1c85fc.tar.gz
Merge pull request #2708 from nanoant/patch/dont-convert-subtype-typedesc-params
Fix #2662: Don't convert subtype typedesc params
-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