Don't blow up with recursive objects
This commit is contained in:
parent
af66258dca
commit
e39baf46fc
2 changed files with 18 additions and 4 deletions
|
|
@ -193,16 +193,15 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
|
||||||
# generated object names can be identical, so we need to
|
# generated object names can be identical, so we need to
|
||||||
# disambiguate furthermore by hashing the field types and names:
|
# disambiguate furthermore by hashing the field types and names:
|
||||||
# mild hack to prevent endless recursions (makes nimforum compile again):
|
# mild hack to prevent endless recursions (makes nimforum compile again):
|
||||||
let wasAnon = sfAnon in t.sym.flags
|
let oldFlags = t.sym.flags
|
||||||
excl t.sym.flags, sfAnon
|
t.sym.flags = t.sym.flags - {sfAnon, sfGenSym}
|
||||||
let n = t.n
|
let n = t.n
|
||||||
for i in 0 ..< n.len:
|
for i in 0 ..< n.len:
|
||||||
assert n[i].kind == nkSym
|
assert n[i].kind == nkSym
|
||||||
let s = n[i].sym
|
let s = n[i].sym
|
||||||
c.hashSym s
|
c.hashSym s
|
||||||
c.hashType s.typ, flags
|
c.hashType s.typ, flags
|
||||||
if wasAnon:
|
t.sym.flags = oldFlags
|
||||||
incl t.sym.flags, sfAnon
|
|
||||||
else:
|
else:
|
||||||
c &= t.id
|
c &= t.id
|
||||||
if t.len > 0 and t.sons[0] != nil:
|
if t.len > 0 and t.sons[0] != nil:
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ discard """
|
||||||
output: '''
|
output: '''
|
||||||
(member: "hello world")
|
(member: "hello world")
|
||||||
(member: 123.456)
|
(member: 123.456)
|
||||||
|
(member: "hello world", x: ...)
|
||||||
|
(member: 123.456, x: ...)
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -16,3 +18,16 @@ template foobar(arg: typed): untyped =
|
||||||
|
|
||||||
foobar("hello world")
|
foobar("hello world")
|
||||||
foobar(123.456'f64)
|
foobar(123.456'f64)
|
||||||
|
|
||||||
|
template foobarRec(arg: typed): untyped =
|
||||||
|
type
|
||||||
|
MyType = object
|
||||||
|
member: type(arg)
|
||||||
|
x: ref MyType
|
||||||
|
|
||||||
|
var myVar: MyType
|
||||||
|
myVar.member = arg
|
||||||
|
echo myVar
|
||||||
|
|
||||||
|
foobarRec("hello world")
|
||||||
|
foobarRec(123.456'f64)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue