Stabilizing go/scanner.(*ErrorList).Sort

68 views
Skip to first unread message

Jan Mercl

unread,
Mar 31, 2015, 4:07:40 AM3/31/15
to golang-nuts
I'm getting diffs from some tests like this:

        -testdata/foo.go:19:44: "bar"
         testdata/foo.go:19:44: "qux"
        +testdata/foo.go:19:44: "bar"

This is because (*ErrorList).Less does not consider the Msg field.

I'd like to propose to consider the Msg field iff all other properties of the compared items a, b compare as !(a < b).

AFAICS, the change is backward compatible and should not break existing code. If approved, I'm happy to submit a CL; provided the Go team does not prefer otherwise.

-j

Jan Mercl

unread,
Mar 31, 2015, 4:26:27 AM3/31/15
to golang-nuts
On Tue, Mar 31, 2015 at 10:06 AM Jan Mercl <0xj...@gmail.com> wrote:

> iff all other properties of the compared items a, b compare as !(a < b).

s/!(a < b)/equal/

ie. this seems to work for me

diff --git a/src/go/scanner/errors.go b/src/go/scanner/errors.go
index 22de69c..7c9ab25 100644
--- a/src/go/scanner/errors.go
+++ b/src/go/scanner/errors.go
@@ -62,7 +62,14 @@ func (p ErrorList) Less(i, j int) bool {
                        return true
                }
                if e.Line == f.Line {
-                       return e.Column < f.Column
+                       if e.Column < f.Column {
+                               return true
+                       }
+                       if e.Column == f.Column {
+                               if p[i].Msg < p[j].Msg {
+                                       return true
+                               }
+                       }
                }
        }
        return false

-j

David Symonds

unread,
Mar 31, 2015, 11:38:34 AM3/31/15
to Jan Mercl, golang-nuts
It seems reasonable to me. Send a CL to gri.
Reply all
Reply to author
Forward
0 new messages