aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/internal
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2019-03-18 20:27:59 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2019-03-18 20:27:59 +0000
commita8b58d84bf4fd9c925a835ba39c1c552383bc61b (patch)
tree97d68e0e70fb780b04f3171a0f53102a39c23f41 /libgo/go/internal
parent891cd9e3b9a89b0461fb838d38c51b6fab596337 (diff)
downloadgcc-a8b58d84bf4fd9c925a835ba39c1c552383bc61b.zip
gcc-a8b58d84bf4fd9c925a835ba39c1c552383bc61b.tar.gz
gcc-a8b58d84bf4fd9c925a835ba39c1c552383bc61b.tar.bz2
libgo: update to Go 1.12.1
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/167749 From-SVN: r269780
Diffstat (limited to 'libgo/go/internal')
-rw-r--r--libgo/go/internal/fmtsort/sort.go2
-rw-r--r--libgo/go/internal/fmtsort/sort_test.go42
2 files changed, 39 insertions, 5 deletions
diff --git a/libgo/go/internal/fmtsort/sort.go b/libgo/go/internal/fmtsort/sort.go
index c959cbe..70a305a 100644
--- a/libgo/go/internal/fmtsort/sort.go
+++ b/libgo/go/internal/fmtsort/sort.go
@@ -167,7 +167,7 @@ func compare(aVal, bVal reflect.Value) int {
if c, ok := nilCompare(aVal, bVal); ok {
return c
}
- c := compare(reflect.ValueOf(aType), reflect.ValueOf(bType))
+ c := compare(reflect.ValueOf(aVal.Elem().Type()), reflect.ValueOf(bVal.Elem().Type()))
if c != 0 {
return c
}
diff --git a/libgo/go/internal/fmtsort/sort_test.go b/libgo/go/internal/fmtsort/sort_test.go
index 6b10c77..e060d4b 100644
--- a/libgo/go/internal/fmtsort/sort_test.go
+++ b/libgo/go/internal/fmtsort/sort_test.go
@@ -126,10 +126,6 @@ var sortTests = []sortTest{
map[[2]int]string{{7, 2}: "72", {7, 1}: "71", {3, 4}: "34"},
"[3 4]:34 [7 1]:71 [7 2]:72",
},
- {
- map[interface{}]string{7: "7", 4: "4", 3: "3", nil: "nil"},
- "<nil>:nil 3:3 4:4 7:7",
- },
}
func sprint(data interface{}) string {
@@ -210,3 +206,41 @@ func TestOrder(t *testing.T) {
}
}
}
+
+func TestInterface(t *testing.T) {
+ // A map containing multiple concrete types should be sorted by type,
+ // then value. However, the relative ordering of types is unspecified,
+ // so test this by checking the presence of sorted subgroups.
+ m := map[interface{}]string{
+ [2]int{1, 0}: "",
+ [2]int{0, 1}: "",
+ true: "",
+ false: "",
+ 3.1: "",
+ 2.1: "",
+ 1.1: "",
+ math.NaN(): "",
+ 3: "",
+ 2: "",
+ 1: "",
+ "c": "",
+ "b": "",
+ "a": "",
+ struct{ x, y int }{1, 0}: "",
+ struct{ x, y int }{0, 1}: "",
+ }
+ got := sprint(m)
+ typeGroups := []string{
+ "NaN: 1.1: 2.1: 3.1:", // float64
+ "false: true:", // bool
+ "1: 2: 3:", // int
+ "a: b: c:", // string
+ "[0 1]: [1 0]:", // [2]int
+ "{0 1}: {1 0}:", // struct{ x int; y int }
+ }
+ for _, g := range typeGroups {
+ if !strings.Contains(got, g) {
+ t.Errorf("sorted map should contain %q", g)
+ }
+ }
+}