summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorzah <zahary@gmail.com>2017-03-17 18:11:37 +0200
committerAndreas Rumpf <rumpf_a@web.de>2017-03-17 17:11:37 +0100
commita20a8e6adb9847cdbae2862a004d762a28d8c454 (patch)
tree8fa539589fc83d9fdb0ba50707a9cc083cd302a5
parentd701de5733f2d1294206df5f2efedfbb62a0f28c (diff)
downloadNim-a20a8e6adb9847cdbae2862a004d762a28d8c454.tar.gz
fixes #4756 (#5557)
-rw-r--r--compiler/sigmatch.nim8
-rw-r--r--tests/errmsgs/t4756.nim16
2 files changed, 22 insertions, 2 deletions
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index bc9888df9..ae7be3c6d 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -1086,8 +1086,12 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
   of tyBuiltInTypeClass:
     considerPreviousT:
       let targetKind = f.sons[0].kind
-      if targetKind == a.skipTypes({tyRange, tyGenericInst, tyBuiltInTypeClass, tyAlias}).kind or
-         (targetKind in {tyProc, tyPointer} and a.kind == tyNil):
+      let effectiveArgType = a.skipTypes({tyRange, tyGenericInst,
+                                          tyBuiltInTypeClass, tyAlias})
+      let typeClassMatches = targetKind == effectiveArgType.kind and
+                             not effectiveArgType.isEmptyContainer
+      if typeClassMatches or
+        (targetKind in {tyProc, tyPointer} and effectiveArgType.kind == tyNil):
         put(c, f, a)
         return isGeneric
       else:
diff --git a/tests/errmsgs/t4756.nim b/tests/errmsgs/t4756.nim
new file mode 100644
index 000000000..91fc90f4b
--- /dev/null
+++ b/tests/errmsgs/t4756.nim
@@ -0,0 +1,16 @@
+discard """
+errormsg: "type mismatch: got (string, arr: seq[empty])"
+line: 15
+"""
+
+# https://github.com/nim-lang/Nim/issues/4756
+
+type
+  Test* = ref object
+    name*: string
+
+proc newTest(name: string, arr: seq): Test =
+    result = Test(name: name)
+
+let test = newTest("test", arr = @[])
+