Skip to content

Ensure that sorting of variables is stable #681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions compiler/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,12 @@ func (c *funcContext) handleEscapingVars(n ast.Node) {

var names []string
objs := analysis.EscapingObjects(n, c.p.Info.Info)
sort.Sort(varsByName(objs))
sort.Slice(objs, func(i, j int) bool {
if objs[i].Name() == objs[j].Name() {
return objs[i].Pos() < objs[j].Pos()
}
return objs[i].Name() < objs[j].Name()
})
for _, obj := range objs {
names = append(names, c.objectName(obj))
c.p.escapingVars[obj] = true
Expand Down Expand Up @@ -638,17 +643,3 @@ func endsWithReturn(stmts []ast.Stmt) bool {
func encodeIdent(name string) string {
return strings.Replace(url.QueryEscape(name), "%", "$", -1)
}

type varsByName []*types.Var

func (s varsByName) Len() int {
return len(s)
}

func (s varsByName) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

func (s varsByName) Less(i, j int) bool {
return s[i].Name() < s[j].Name()
}