summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorandri lim <jangko128@gmail.com>2018-04-27 13:53:20 +0700
committerAndreas Rumpf <rumpf_a@web.de>2018-04-27 08:53:20 +0200
commite4aa140d22fe065bee78a1edaadbd5bae3160779 (patch)
treedd9b45342551283254b2a08d2cc89064348fabb5
parent397e1731393be598991df302006ec3634baa3583 (diff)
downloadNim-e4aa140d22fe065bee78a1edaadbd5bae3160779.tar.gz
fixes #7600, generic object with generic ref object parent typerel bug (#7678)
* fixes #7600

* fix wrong logic
-rw-r--r--compiler/sigmatch.nim9
-rw-r--r--tests/typerel/t7600_1.nim18
-rw-r--r--tests/typerel/t7600_2.nim17
3 files changed, 42 insertions, 2 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 96d815df7..552d2cdca 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -1388,8 +1388,13 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
 
         var aAsObject = roota.lastSon
 
-        if fKind in {tyRef, tyPtr} and aAsObject.kind == fKind:
-          aAsObject = aAsObject.base
+        if fKind in {tyRef, tyPtr}:
+          if aAsObject.kind == tyObject:
+            # bug #7600, tyObject cannot be passed
+            # as argument to tyRef/tyPtr
+            return isNone
+          elif aAsObject.kind == fKind:
+            aAsObject = aAsObject.base
 
         if aAsObject.kind == tyObject:
           let baseType = aAsObject.base
diff --git a/tests/typerel/t7600_1.nim b/tests/typerel/t7600_1.nim
new file mode 100644
index 000000000..e3a5fefa2
--- /dev/null
+++ b/tests/typerel/t7600_1.nim
@@ -0,0 +1,18 @@
+discard """
+errormsg: "type mismatch: got <Thin[system.int]>"
+nimout: '''t7600_1.nim(18, 6) Error: type mismatch: got <Thin[system.int]>
+but expected one of:
+proc test[T](x: Paper[T])
+
+expression: test tn'''
+"""
+
+type
+  Paper[T] = ref object of RootObj
+    thickness: T
+  Thin[T]  = object of Paper[T]
+
+proc test[T](x: Paper[T]) = discard
+
+var tn = Thin[int]()
+test tn
diff --git a/tests/typerel/t7600_2.nim b/tests/typerel/t7600_2.nim
new file mode 100644
index 000000000..7badb69cf
--- /dev/null
+++ b/tests/typerel/t7600_2.nim
@@ -0,0 +1,17 @@
+discard """
+errormsg: "type mismatch: got <Thin>"
+nimout: '''t7600_2.nim(17, 6) Error: type mismatch: got <Thin>
+but expected one of:
+proc test(x: Paper)
+
+expression: test tn'''
+"""
+
+type
+  Paper = ref object of RootObj
+  Thin  = object of Paper
+
+proc test(x: Paper) = discard
+
+var tn = Thin()
+test tn