fixes #5147
This commit is contained in:
parent
700c024e13
commit
4104ee121d
2 changed files with 35 additions and 7 deletions
|
|
@ -82,6 +82,13 @@ else:
|
||||||
result = 0
|
result = 0
|
||||||
for x in 0..3:
|
for x in 0..3:
|
||||||
result = (result shl 8) or u.MD5Digest[x].int
|
result = (result shl 8) or u.MD5Digest[x].int
|
||||||
|
type
|
||||||
|
ConsiderFlag* = enum
|
||||||
|
CoProc
|
||||||
|
CoType
|
||||||
|
CoOwnerSig
|
||||||
|
|
||||||
|
proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag])
|
||||||
|
|
||||||
proc hashSym(c: var MD5Context, s: PSym) =
|
proc hashSym(c: var MD5Context, s: PSym) =
|
||||||
if sfAnon in s.flags or s.kind == skGenericParam:
|
if sfAnon in s.flags or s.kind == skGenericParam:
|
||||||
|
|
@ -93,6 +100,19 @@ proc hashSym(c: var MD5Context, s: PSym) =
|
||||||
c &= "."
|
c &= "."
|
||||||
it = it.owner
|
it = it.owner
|
||||||
|
|
||||||
|
proc hashTypeSym(c: var MD5Context, s: PSym) =
|
||||||
|
if sfAnon in s.flags or s.kind == skGenericParam:
|
||||||
|
c &= ":anon"
|
||||||
|
else:
|
||||||
|
var it = s
|
||||||
|
while it != nil:
|
||||||
|
if sfFromGeneric in it.flags and it.kind in routineKinds and
|
||||||
|
it.typ != nil:
|
||||||
|
hashType c, it.typ, {CoProc}
|
||||||
|
c &= it.name.s
|
||||||
|
c &= "."
|
||||||
|
it = it.owner
|
||||||
|
|
||||||
proc hashTree(c: var MD5Context, n: PNode) =
|
proc hashTree(c: var MD5Context, n: PNode) =
|
||||||
if n == nil:
|
if n == nil:
|
||||||
c &= "\255"
|
c &= "\255"
|
||||||
|
|
@ -118,11 +138,6 @@ proc hashTree(c: var MD5Context, n: PNode) =
|
||||||
else:
|
else:
|
||||||
for i in 0.. <n.len: hashTree(c, n.sons[i])
|
for i in 0.. <n.len: hashTree(c, n.sons[i])
|
||||||
|
|
||||||
type
|
|
||||||
ConsiderFlag* = enum
|
|
||||||
CoProc
|
|
||||||
CoType
|
|
||||||
|
|
||||||
proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
|
proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
|
||||||
if t == nil:
|
if t == nil:
|
||||||
c &= "\254"
|
c &= "\254"
|
||||||
|
|
@ -163,6 +178,9 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
|
||||||
# writeStackTrace()
|
# writeStackTrace()
|
||||||
# echo "yes ", t.sym.name.s
|
# echo "yes ", t.sym.name.s
|
||||||
# #quit 1
|
# #quit 1
|
||||||
|
if CoOwnerSig in flags:
|
||||||
|
c.hashTypeSym(t.sym)
|
||||||
|
else:
|
||||||
c.hashSym(t.sym)
|
c.hashSym(t.sym)
|
||||||
if sfAnon in t.sym.flags:
|
if sfAnon in t.sym.flags:
|
||||||
# generated object names can be identical, so we need to
|
# generated object names can be identical, so we need to
|
||||||
|
|
@ -246,7 +264,7 @@ when defined(debugSigHashes):
|
||||||
proc hashType*(t: PType; flags: set[ConsiderFlag] = {CoType}): SigHash =
|
proc hashType*(t: PType; flags: set[ConsiderFlag] = {CoType}): SigHash =
|
||||||
var c: MD5Context
|
var c: MD5Context
|
||||||
md5Init c
|
md5Init c
|
||||||
hashType c, t, flags
|
hashType c, t, flags+{CoOwnerSig}
|
||||||
md5Final c, result.Md5Digest
|
md5Final c, result.Md5Digest
|
||||||
when defined(debugSigHashes):
|
when defined(debugSigHashes):
|
||||||
db.exec(sql"INSERT OR IGNORE INTO sighashes(type, hash) VALUES (?, ?)",
|
db.exec(sql"INSERT OR IGNORE INTO sighashes(type, hash) VALUES (?, ?)",
|
||||||
|
|
|
||||||
10
tests/ccgbugs/tsighash_typename_regression.nim
Normal file
10
tests/ccgbugs/tsighash_typename_regression.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
# bug #5147
|
||||||
|
|
||||||
|
proc foo[T](t: T) =
|
||||||
|
type Wrapper = object
|
||||||
|
get: T
|
||||||
|
let w = Wrapper(get: t)
|
||||||
|
echo w.get
|
||||||
|
|
||||||
|
foo(123)
|
||||||
|
foo("baz")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue