Discriminate gensym'd type names in sigHash
The root cause of #7905 lies in the codegen phase. The two template instantiations generate two different MyType types with different members but same t.sym.name leading the caching mechanism to confuse the two. Fixes #7905
This commit is contained in:
parent
0da87939d1
commit
af66258dca
2 changed files with 22 additions and 2 deletions
|
|
@ -189,10 +189,11 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
|
||||||
c.hashTypeSym(t.sym)
|
c.hashTypeSym(t.sym)
|
||||||
else:
|
else:
|
||||||
c.hashSym(t.sym)
|
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
|
# 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
|
||||||
excl t.sym.flags, sfAnon
|
excl t.sym.flags, sfAnon
|
||||||
let n = t.n
|
let n = t.n
|
||||||
for i in 0 ..< n.len:
|
for i in 0 ..< n.len:
|
||||||
|
|
@ -200,7 +201,8 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
|
||||||
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
|
||||||
incl t.sym.flags, sfAnon
|
if wasAnon:
|
||||||
|
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:
|
||||||
|
|
|
||||||
18
tests/types/t7905.nim
Normal file
18
tests/types/t7905.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
discard """
|
||||||
|
output: '''
|
||||||
|
(member: "hello world")
|
||||||
|
(member: 123.456)
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue