mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-25 04:15:09 +00:00
fixes #232
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"
|
||||
#]
|
||||
|
||||
Reference in New Issue
Block a user