mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-01 19:02:18 +00:00
Merge pull request #8084 from LemonBoy/fix-7905
Discriminate gensym'd type names in sigHash
This commit is contained in:
@@ -189,18 +189,19 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
|
||||
c.hashTypeSym(t.sym)
|
||||
else:
|
||||
c.hashSym(t.sym)
|
||||
if sfAnon in t.sym.flags:
|
||||
if {sfAnon, sfGenSym} * t.sym.flags != {}:
|
||||
# generated object names can be identical, so we need to
|
||||
# disambiguate furthermore by hashing the field types and names:
|
||||
# mild hack to prevent endless recursions (makes nimforum compile again):
|
||||
excl t.sym.flags, sfAnon
|
||||
let oldFlags = t.sym.flags
|
||||
t.sym.flags = t.sym.flags - {sfAnon, sfGenSym}
|
||||
let n = t.n
|
||||
for i in 0 ..< n.len:
|
||||
assert n[i].kind == nkSym
|
||||
let s = n[i].sym
|
||||
c.hashSym s
|
||||
c.hashType s.typ, flags
|
||||
incl t.sym.flags, sfAnon
|
||||
t.sym.flags = oldFlags
|
||||
else:
|
||||
c &= t.id
|
||||
if t.len > 0 and t.sons[0] != nil:
|
||||
|
||||
33
tests/types/t7905.nim
Normal file
33
tests/types/t7905.nim
Normal file
@@ -0,0 +1,33 @@
|
||||
discard """
|
||||
output: '''
|
||||
(member: "hello world")
|
||||
(member: 123.456)
|
||||
(member: "hello world", x: ...)
|
||||
(member: 123.456, x: ...)
|
||||
'''
|
||||
"""
|
||||
|
||||
template foobar(arg: typed): untyped =
|
||||
type
|
||||
MyType = object
|
||||
member: type(arg)
|
||||
|
||||
var myVar: MyType
|
||||
myVar.member = arg
|
||||
echo myVar
|
||||
|
||||
foobar("hello world")
|
||||
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)
|
||||
Reference in New Issue
Block a user