Skip to content

Commit

Permalink
compiler: walk over functions in reproducible order, fix #3219
Browse files Browse the repository at this point in the history
It affects both Debug data and bindings, otherwise two unnamed structures can
get any of unnamed/unnamedx names depending on particular invocation.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
  • Loading branch information
roman-khimov committed Nov 23, 2023
1 parent 25ef2c7 commit 341d978
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pkg/compiler/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,19 @@ func (c *codegen) emitDebugInfo(contract []byte) *DebugInfo {
})
}

start := len(d.Methods)
d.NamedTypes = make(map[string]binding.ExtendedType)
var fnames = make([]string, 0, len(c.funcs))
for name, scope := range c.funcs {
if scope.rng.Start == scope.rng.End {
continue
}
m := c.methodInfoFromScope(name, scope, d.NamedTypes)
fnames = append(fnames, name)
}
sort.Strings(fnames)
d.NamedTypes = make(map[string]binding.ExtendedType)
for _, name := range fnames {
m := c.methodInfoFromScope(name, c.funcs[name], d.NamedTypes)
d.Methods = append(d.Methods, *m)
}
sort.Slice(d.Methods[start:], func(i, j int) bool {
return d.Methods[start+i].Name.Name < d.Methods[start+j].Name.Name
})
d.EmittedEvents = c.emittedEvents
d.InvokedContracts = c.invokedContracts
return d
Expand Down

0 comments on commit 341d978

Please sign in to comment.