]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: print underlying type of comparable as "interface{comparable}"
authorRobert Griesemer <gri@golang.org>
Tue, 25 Jan 2022 17:21:39 +0000 (09:21 -0800)
committerRobert Griesemer <gri@golang.org>
Wed, 26 Jan 2022 22:09:36 +0000 (22:09 +0000)
For #50791.

Change-Id: Ib12009d2895146e55ec3a51aa8ceafe58dfd82a5
Reviewed-on: https://go-review.googlesource.com/c/go/+/380754
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/typestring.go
src/cmd/compile/internal/types2/typestring_test.go
src/go/types/typestring.go
src/go/types/typestring_test.go

index 4d03eba65757c0ceaac89f2f358754102d88f67c..ada0529929972467bf7c312d21100cda99001e39 100644 (file)
@@ -201,12 +201,18 @@ func (w *typeWriter) typ(typ Type) {
                }
 
        case *Interface:
-               if t == universeAny.Type() && w.ctxt == nil {
-                       // When not hashing, we can try to improve type strings by writing "any"
-                       // for a type that is pointer-identical to universeAny. This logic should
-                       // be deprecated by more robust handling for aliases.
-                       w.string("any")
-                       break
+               if w.ctxt == nil {
+                       if t == universeAny.Type() {
+                               // When not hashing, we can try to improve type strings by writing "any"
+                               // for a type that is pointer-identical to universeAny. This logic should
+                               // be deprecated by more robust handling for aliases.
+                               w.string("any")
+                               break
+                       }
+                       if t == universeComparable.Type().(*Named).underlying {
+                               w.string("interface{comparable}")
+                               break
+                       }
                }
                if t.implicit {
                        if len(t.methods) == 0 && len(t.embeddeds) == 1 {
index eda68355884ceeaa5ed4d61c51b3badca56d3419..c0689e866c913599a991e10e37bf02b4d655f447 100644 (file)
@@ -93,6 +93,10 @@ var independentTestTypes = []testEntry{
        dup(`interface{String() string; m(int) float32}`),
        dup("interface{int|float32|complex128}"),
        dup("interface{int|~float32|~complex128}"),
+       dup("any"),
+       dup("interface{comparable}"),
+       {"comparable", "interface{comparable}"},
+       {"error", "interface{Error() string}"},
 
        // maps
        dup("map[string]int"),
index cf86f9f72086fee21a669bd135a7cf404fe8d664..80210a2f34cd71981b47feb59f0ce46ed40f7efe 100644 (file)
@@ -202,12 +202,18 @@ func (w *typeWriter) typ(typ Type) {
                }
 
        case *Interface:
-               if t == universeAny.Type() && w.ctxt == nil {
-                       // When not hashing, we can try to improve type strings by writing "any"
-                       // for a type that is pointer-identical to universeAny. This logic should
-                       // be deprecated by more robust handling for aliases.
-                       w.string("any")
-                       break
+               if w.ctxt == nil {
+                       if t == universeAny.Type() {
+                               // When not hashing, we can try to improve type strings by writing "any"
+                               // for a type that is pointer-identical to universeAny. This logic should
+                               // be deprecated by more robust handling for aliases.
+                               w.string("any")
+                               break
+                       }
+                       if t == universeComparable.Type().(*Named).underlying {
+                               w.string("interface{comparable}")
+                               break
+                       }
                }
                if t.implicit {
                        if len(t.methods) == 0 && len(t.embeddeds) == 1 {
index 14ab9b6002a5185eed4bebfea937a27841e7992b..b7b843516e1283e66e06c217f5abfc8c737c08b6 100644 (file)
@@ -97,6 +97,11 @@ var independentTestTypes = []testEntry{
        dup(`interface{String() string; m(int) float32}`),
        dup("interface{int|float32|complex128}"),
        dup("interface{int|~float32|~complex128}"),
+       dup("any"),
+       dup("interface{comparable}"),
+       // TODO(gri) adjust test for EvalCompositeTest
+       // {"comparable", "interface{comparable}"},
+       // {"error", "interface{Error() string}"},
 
        // maps
        dup("map[string]int"),