parent
08a954f7ee
commit
32ec5af60a
3 changed files with 72 additions and 11 deletions
|
|
@ -20,7 +20,7 @@ proc int64Literal(i: BiggestInt): PRope =
|
||||||
proc uint64Literal(i: uint64): PRope = toRope($i & "ULL")
|
proc uint64Literal(i: uint64): PRope = toRope($i & "ULL")
|
||||||
|
|
||||||
proc intLiteral(i: BiggestInt): PRope =
|
proc intLiteral(i: BiggestInt): PRope =
|
||||||
if (i > low(int32)) and (i <= high(int32)):
|
if i > low(int32) and i <= high(int32):
|
||||||
result = toRope(i)
|
result = toRope(i)
|
||||||
elif i == low(int32):
|
elif i == low(int32):
|
||||||
# Nim has the same bug for the same reasons :-)
|
# Nim has the same bug for the same reasons :-)
|
||||||
|
|
@ -39,7 +39,7 @@ proc int32Literal(i: int): PRope =
|
||||||
proc genHexLiteral(v: PNode): PRope =
|
proc genHexLiteral(v: PNode): PRope =
|
||||||
# hex literals are unsigned in C
|
# hex literals are unsigned in C
|
||||||
# so we don't generate hex literals any longer.
|
# so we don't generate hex literals any longer.
|
||||||
if not (v.kind in {nkIntLit..nkUInt64Lit}):
|
if v.kind notin {nkIntLit..nkUInt64Lit}:
|
||||||
internalError(v.info, "genHexLiteral")
|
internalError(v.info, "genHexLiteral")
|
||||||
result = intLiteral(v.intVal)
|
result = intLiteral(v.intVal)
|
||||||
|
|
||||||
|
|
@ -328,7 +328,9 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src))
|
linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(dest), rdLoc(src))
|
||||||
of tyObject:
|
of tyObject:
|
||||||
# XXX: check for subtyping?
|
# XXX: check for subtyping?
|
||||||
if needsComplexAssignment(ty):
|
if not isObjLackingTypeField(ty):
|
||||||
|
genGenericAsgn(p, dest, src, flags)
|
||||||
|
elif needsComplexAssignment(ty):
|
||||||
if ty.sons[0].isNil and asgnComplexity(ty.n) <= 4:
|
if ty.sons[0].isNil and asgnComplexity(ty.n) <= 4:
|
||||||
discard getTypeDesc(p.module, ty)
|
discard getTypeDesc(p.module, ty)
|
||||||
internalAssert ty.n != nil
|
internalAssert ty.n != nil
|
||||||
|
|
|
||||||
|
|
@ -70,13 +70,17 @@ proc genericAssignAux(dest, src: pointer, mt: PNimType, shallow: bool) =
|
||||||
GenericSeqSize),
|
GenericSeqSize),
|
||||||
mt.base, shallow)
|
mt.base, shallow)
|
||||||
of tyObject:
|
of tyObject:
|
||||||
# we need to copy m_type field for tyObject, as it could be empty for
|
|
||||||
# sequence reallocations:
|
|
||||||
var pint = cast[ptr PNimType](dest)
|
|
||||||
pint[] = cast[ptr PNimType](src)[]
|
|
||||||
if mt.base != nil:
|
if mt.base != nil:
|
||||||
genericAssignAux(dest, src, mt.base, shallow)
|
genericAssignAux(dest, src, mt.base, shallow)
|
||||||
genericAssignAux(dest, src, mt.node, shallow)
|
genericAssignAux(dest, src, mt.node, shallow)
|
||||||
|
# we need to copy m_type field for tyObject, as it could be empty for
|
||||||
|
# sequence reallocations:
|
||||||
|
var pint = cast[ptr PNimType](dest)
|
||||||
|
# We need to copy the *static* type not the dynamic type:
|
||||||
|
# if p of TB:
|
||||||
|
# var tbObj = TB(p)
|
||||||
|
# tbObj of TC # needs to be false!
|
||||||
|
pint[] = mt # cast[ptr PNimType](src)[]
|
||||||
of tyTuple:
|
of tyTuple:
|
||||||
genericAssignAux(dest, src, mt.node, shallow)
|
genericAssignAux(dest, src, mt.node, shallow)
|
||||||
of tyArray, tyArrayConstr:
|
of tyArray, tyArrayConstr:
|
||||||
|
|
|
||||||
55
tests/objects/tinherentedvalues.nim
Normal file
55
tests/objects/tinherentedvalues.nim
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
discard """
|
||||||
|
output: '''tbObj of TC false
|
||||||
|
false
|
||||||
|
true
|
||||||
|
5
|
||||||
|
false'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #1053
|
||||||
|
type
|
||||||
|
TA = object of TObject
|
||||||
|
a: int
|
||||||
|
|
||||||
|
TB = object of TA
|
||||||
|
b: int
|
||||||
|
|
||||||
|
TC = object of TB
|
||||||
|
c: int
|
||||||
|
|
||||||
|
proc test(p: TA) =
|
||||||
|
#echo "p of TB ", p of TB
|
||||||
|
if p of TB:
|
||||||
|
var tbObj = TB(p)
|
||||||
|
|
||||||
|
# tbObj is actually no longer compatible with TC:
|
||||||
|
echo "tbObj of TC ", tbObj of TC
|
||||||
|
|
||||||
|
var v = TC()
|
||||||
|
v.a = 1
|
||||||
|
v.b = 2
|
||||||
|
v.c = 3
|
||||||
|
test(v)
|
||||||
|
|
||||||
|
|
||||||
|
# bug #924
|
||||||
|
type
|
||||||
|
MyObject = object of TObject
|
||||||
|
x: int
|
||||||
|
|
||||||
|
var
|
||||||
|
asd: MyObject
|
||||||
|
|
||||||
|
proc isMyObject(obj: TObject) =
|
||||||
|
echo obj of MyObject
|
||||||
|
if obj of MyObject:
|
||||||
|
let a = MyObject(obj)
|
||||||
|
echo a.x
|
||||||
|
|
||||||
|
asd.x = 5
|
||||||
|
|
||||||
|
var asdCopy = TObject(asd)
|
||||||
|
echo asdCopy of MyObject
|
||||||
|
|
||||||
|
isMyObject(asd)
|
||||||
|
isMyObject(asdCopy)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue