diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index d6666d88b9..72d95c4c73 100755 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1036,6 +1036,9 @@ proc genOf(p: BProc, x: PNode, typ: PType, d: var TLoc) = while (t.kind == tyObject) and (t.sons[0] != nil): app(r, ".Sup") t = skipTypes(t.sons[0], typedescInst) + if isObjLackingTypeField(t): + GlobalError(x.info, errGenerated, + "no 'of' operator available for pure objects") if nilCheck != nil: r = ropecg(p.module, "(($1) && #isObj($2.m_type, $3))", [nilCheck, r, genTypeInfo(p.module, dest)]) @@ -1597,7 +1600,7 @@ proc upConv(p: BProc, n: PNode, d: var TLoc) = var a: TLoc initLocExpr(p, n.sons[0], a) var dest = skipTypes(n.typ, abstractPtrs) - if optObjCheck in p.options and not isPureObject(dest): + if optObjCheck in p.options and not isObjLackingTypeField(dest): var r = rdLoc(a) var nilCheck: PRope = nil var t = skipTypes(a.t, abstractInst) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 0ab4ff2006..0495c33fb9 100755 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -694,11 +694,14 @@ when false: var tmp = getNimType(m) appf(m.s[cfsTypeInit2], "$2 = &$1;$n", [tmp, name]) +proc isObjLackingTypeField(typ: PType): bool {.inline.} = + result = (typ.kind == tyObject) and ((tfFinal in typ.flags) and + (typ.sons[0] == nil) or isPureObject(typ)) + proc genTypeInfoAuxBase(m: BModule, typ: PType, name, base: PRope) = var nimtypeKind: int #allocMemTI(m, typ, name) - if (typ.kind == tyObject) and (tfFinal in typ.flags) and - (typ.sons[0] == nil): + if isObjLackingTypeField(typ): nimtypeKind = ord(tyPureObject) else: nimtypeKind = ord(typ.kind) diff --git a/lib/system/repr.nim b/lib/system/repr.nim index 028887b4c9..3c9ce73acd 100755 --- a/lib/system/repr.nim +++ b/lib/system/repr.nim @@ -185,7 +185,11 @@ when not defined(useNimRtl): proc reprRecord(result: var string, p: pointer, typ: PNimType, cl: var TReprClosure) = add result, "[" + let oldLen = result.len reprRecordAux(result, p, typ.node, cl) + if typ.base != nil: + if oldLen != result.len: add result, ",\n" + reprRecordAux(result, p, typ.base.node, cl) add result, "]" proc reprRef(result: var string, p: pointer, typ: PNimType, diff --git a/tests/run/trepr.nim b/tests/run/trepr.nim index 622c9c78a2..41c830621b 100755 --- a/tests/run/trepr.nim +++ b/tests/run/trepr.nim @@ -11,6 +11,17 @@ var val = {a, b} stdout.write(repr(val)) stdout.writeln(repr({'a'..'z', 'A'..'Z'})) +type + TObj {.pure, inheritable.} = object + data: int + TFoo = ref object of TObj + d2: float +var foo: TFoo +new(foo) + +when false: + # cannot capture this output as it contains a memory address :-/ + echo foo.repr #var testseq: seq[string] = @[ # "a", "b", "c", "d", "e" #]