summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rwxr-xr-xcompiler/ccgexprs.nim6
-rwxr-xr-xcompiler/ccgtypes.nim7
-rwxr-xr-xcompiler/ecmasgen.nim2
-rwxr-xr-xcompiler/semexprs.nim15
-rwxr-xr-xcompiler/types.nim3
5 files changed, 20 insertions, 13 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index ed84a3126..81ac72aa8 100755
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -1024,18 +1024,18 @@ proc genNewFinalize(p: BProc, e: PNode) =
 proc genOf(p: BProc, x: PNode, typ: PType, d: var TLoc) =
   var a: TLoc
   initLocExpr(p, x, a)
-  var dest = skipTypes(typ, abstractPtrs)
+  var dest = skipTypes(typ, typedescPtrs)
   var r = rdLoc(a)
   var nilCheck: PRope = nil
   var t = skipTypes(a.t, abstractInst)
   while t.kind in {tyVar, tyPtr, tyRef}:
     if t.kind != tyVar: nilCheck = r
     r = ropef("(*$1)", [r])
-    t = skipTypes(t.sons[0], abstractInst)
+    t = skipTypes(t.sons[0], typedescInst)
   if gCmd != cmdCompileToCpp:
     while (t.kind == tyObject) and (t.sons[0] != nil):
       app(r, ".Sup")
-      t = skipTypes(t.sons[0], abstractInst)
+      t = skipTypes(t.sons[0], typedescInst)
   if nilCheck != nil:
     r = ropecg(p.module, "(($1) && #isObj($2.m_type, $3))",
               [nilCheck, r, genTypeInfo(p.module, dest)])
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim
index 219c791e2..58525773f 100755
--- a/compiler/ccgtypes.nim
+++ b/compiler/ccgtypes.nim
@@ -174,7 +174,7 @@ proc mapType(typ: PType): TCTypeKind =
   of tyOpenArray, tyArrayConstr, tyArray: result = ctArray
   of tyObject, tyTuple: result = ctStruct
   of tyGenericBody, tyGenericInst, tyGenericParam, tyDistinct, tyOrdinal,
-     tyConst, tyMutable, tyIter: 
+     tyConst, tyMutable, tyIter, tyTypeDesc: 
     result = mapType(lastSon(typ))
   of tyEnum: 
     if firstOrd(typ) < 0: 
@@ -601,9 +601,10 @@ proc getTypeDescAux(m: BModule, typ: PType, check: var TIntSet): PRope =
       if not isImportedType(t): 
         appf(m.s[cfsTypes], "typedef NU8 $1[$2];$n", 
              [result, toRope(getSize(t))])
-  of tyGenericInst, tyDistinct, tyOrdinal, tyConst, tyMutable, tyIter: 
+  of tyGenericInst, tyDistinct, tyOrdinal, tyConst, tyMutable, 
+      tyIter, tyTypeDesc:
     result = getTypeDescAux(m, lastSon(t), check)
-  else: 
+  else:
     InternalError("getTypeDescAux(" & $t.kind & ')')
     result = nil
   # fixes bug #145:
diff --git a/compiler/ecmasgen.nim b/compiler/ecmasgen.nim
index 20a021669..1ae80c74c 100755
--- a/compiler/ecmasgen.nim
+++ b/compiler/ecmasgen.nim
@@ -1185,7 +1185,7 @@ proc genRepr(p: var TProc, n: PNode, r: var TCompRes) =
 
 proc genOf(p: var TProc, n: PNode, r: var TCompRes) =
   var x: TCompRes
-  let t = skipTypes(n.sons[2].typ, abstractVarRange+{tyRef, tyPtr})
+  let t = skipTypes(n.sons[2].typ, abstractVarRange+{tyRef, tyPtr, tyTypeDesc})
   gen(p, n.sons[1], x)
   if tfFinal in t.flags:
     r.res = ropef("($1.m_type == $2)", [x.res, genTypeInfo(p, t)])
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index db61ff79e..0b07d84a9 100755
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -245,11 +245,16 @@ proc semOf(c: PContext, n: PNode): PNode =
   if sonsLen(n) == 3: 
     n.sons[1] = semExprWithType(c, n.sons[1])
     n.sons[2] = semExprWithType(c, n.sons[2])
-    restoreOldStyleType(n.sons[1])
-    restoreOldStyleType(n.sons[2])
-    var a = skipTypes(n.sons[1].typ, abstractPtrs)
-    var b = skipTypes(n.sons[2].typ, abstractPtrs)
-    if b.kind != tyObject or a.kind != tyObject: 
+    #restoreOldStyleType(n.sons[1])
+    #restoreOldStyleType(n.sons[2])
+    let a = skipTypes(n.sons[1].typ, typedescPtrs)
+    let b = skipTypes(n.sons[2].typ, typedescPtrs)
+    let x = skipTypes(n.sons[1].typ, abstractPtrs)
+    let y = skipTypes(n.sons[2].typ, abstractPtrs)
+
+    if x.kind == tyTypeDesc or y.kind != tyTypeDesc:
+      GlobalError(n.info, errXExpectsObjectTypes, "of")
+    elif b.kind != tyObject or a.kind != tyObject:
       GlobalError(n.info, errXExpectsObjectTypes, "of")
     let diff = inheritanceDiff(a, b)
     # | returns: 0 iff `a` == `b`
diff --git a/compiler/types.nim b/compiler/types.nim
index 23ba85325..02fcf5323 100755
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -59,7 +59,8 @@ const
   abstractInst* = {tyGenericInst, tyDistinct, tyConst, tyMutable, tyOrdinal}
 
   skipPtrs* = {tyVar, tyPtr, tyRef, tyGenericInst, tyConst, tyMutable}
-  typeclassPtrs* = abstractPtrs + {tyTypeClass}
+  typedescPtrs* = abstractPtrs + {tyTypeDesc}
+  typedescInst* = abstractInst + {tyTypeDesc}
 
 proc skipTypes*(t: PType, kinds: TTypeKinds): PType
 proc containsObject*(t: PType): bool