summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2014-01-26 00:45:50 +0200
committerZahary Karadjov <zahary@gmail.com>2014-01-26 00:45:50 +0200
commit5a6030a16bf74ee7de92117c5b2d7310b8b36d28 (patch)
treee82021816274928684f03b4603449d8ce08552fd /compiler
parent3f71b7f1f6db5fbe3c61dde0cfd43d1eb0088cb6 (diff)
downloadNim-5a6030a16bf74ee7de92117c5b2d7310b8b36d28.tar.gz
the `is` operator now uses exactly the same algorithm as proc signature matching
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semexprs.nim25
-rw-r--r--compiler/sigmatch.nim2
2 files changed, 8 insertions, 19 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 1096d3029..84303b6cd 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -322,24 +322,13 @@ proc isOpImpl(c: PContext, n: PNode): PNode =
                                         t.callConv == ccClosure and 
                                         tfIterator in t.flags))
   else:
-    var match: bool
-    let t2 = n[2].typ.skipTypes({tyTypeDesc})
-    case t2.kind
-    of tyTypeClasses:
-      var m: TCandidate
-      initCandidate(c, m, t2)
-      match = typeRel(m, t2, t1) != isNone
-    of tyOrdinal:
-      var m: TCandidate
-      initCandidate(c, m, t2)
-      match = isOrdinalType(t1)
-    of tySequence, tyArray, tySet:
-      var m: TCandidate
-      initCandidate(c, m, t2)
-      match = typeRel(m, t2, t1) != isNone
-    else:
-      match = sameType(t1, t2)
- 
+    var t2 = n[2].typ.skipTypes({tyTypeDesc})
+    let lifted = liftParamType(c, skType, newNodeI(nkArgList, n.info),
+                               t2, ":anon", n.info)
+    if lifted != nil: t2 = lifted
+    var m: TCandidate
+    initCandidate(c, m, t2)
+    let match = typeRel(m, t2, t1) != isNone
     result = newIntNode(nkIntLit, ord(match))
 
   result.typ = n.typ
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 971d526ee..d269e9e69 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -820,7 +820,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
       else:
         return isNone
 
-  of tyUserTypeClassInst:
+  of tyUserTypeClass, tyUserTypeClassInst:
     considerPreviousT:
       result = matchUserTypeClass(c.c, c, f, a)
       if result == isGeneric: