]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: consistently write "x | y" rather than "x|y" for unions
authorRobert Griesemer <gri@golang.org>
Fri, 2 Sep 2022 17:24:53 +0000 (10:24 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 2 Sep 2022 19:22:26 +0000 (19:22 +0000)
Use the same spacing convention ("x | y") for union terms everythere,
matching the gofmt precedent.

Fixes #53279.

Change-Id: Ic3ccd7433b5f62402ba41cf05a75f9a1d99a8086
Reviewed-on: https://go-review.googlesource.com/c/go/+/410955
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
14 files changed:
src/cmd/compile/internal/types2/api_test.go
src/cmd/compile/internal/types2/termlist.go
src/cmd/compile/internal/types2/typestring.go
src/cmd/compile/internal/types2/typestring_test.go
src/go/types/api_test.go
src/go/types/termlist.go
src/go/types/typestring.go
src/go/types/typestring_test.go
src/internal/types/testdata/fixedbugs/issue45920.go
src/internal/types/testdata/fixedbugs/issue47411.go
src/internal/types/testdata/fixedbugs/issue47818.go
src/internal/types/testdata/fixedbugs/issue49179.go
src/internal/types/testdata/fixedbugs/issue51472.go
src/internal/types/testdata/spec/conversions.go

index f5526bb25a38f986da8ba574889a51541621d9c8..9367e5f3f24150abb7e46ab60d3683b17a94f40e 100644 (file)
@@ -358,27 +358,27 @@ func TestTypesInfo(t *testing.T) {
                // issue 50093
                {`package u0a; func _[_ interface{int}]() {}`, `int`, `int`},
                {`package u1a; func _[_ interface{~int}]() {}`, `~int`, `~int`},
-               {`package u2a; func _[_ interface{int|string}]() {}`, `int | string`, `int|string`},
-               {`package u3a; func _[_ interface{int|string|~bool}]() {}`, `int | string | ~bool`, `int|string|~bool`},
-               {`package u3a; func _[_ interface{int|string|~bool}]() {}`, `int | string`, `int|string`},
-               {`package u3a; func _[_ interface{int|string|~bool}]() {}`, `~bool`, `~bool`},
-               {`package u3a; func _[_ interface{int|string|~float64|~bool}]() {}`, `int | string | ~float64`, `int|string|~float64`},
+               {`package u2a; func _[_ interface{int | string}]() {}`, `int | string`, `int | string`},
+               {`package u3a; func _[_ interface{int | string | ~bool}]() {}`, `int | string | ~bool`, `int | string | ~bool`},
+               {`package u3a; func _[_ interface{int | string | ~bool}]() {}`, `int | string`, `int | string`},
+               {`package u3a; func _[_ interface{int | string | ~bool}]() {}`, `~bool`, `~bool`},
+               {`package u3a; func _[_ interface{int | string | ~float64|~bool}]() {}`, `int | string | ~float64`, `int | string | ~float64`},
 
                {`package u0b; func _[_ int]() {}`, `int`, `int`},
                {`package u1b; func _[_ ~int]() {}`, `~int`, `~int`},
-               {`package u2b; func _[_ int|string]() {}`, `int | string`, `int|string`},
-               {`package u3b; func _[_ int|string|~bool]() {}`, `int | string | ~bool`, `int|string|~bool`},
-               {`package u3b; func _[_ int|string|~bool]() {}`, `int | string`, `int|string`},
-               {`package u3b; func _[_ int|string|~bool]() {}`, `~bool`, `~bool`},
-               {`package u3b; func _[_ int|string|~float64|~bool]() {}`, `int | string | ~float64`, `int|string|~float64`},
+               {`package u2b; func _[_ int | string]() {}`, `int | string`, `int | string`},
+               {`package u3b; func _[_ int | string | ~bool]() {}`, `int | string | ~bool`, `int | string | ~bool`},
+               {`package u3b; func _[_ int | string | ~bool]() {}`, `int | string`, `int | string`},
+               {`package u3b; func _[_ int | string | ~bool]() {}`, `~bool`, `~bool`},
+               {`package u3b; func _[_ int | string | ~float64|~bool]() {}`, `int | string | ~float64`, `int | string | ~float64`},
 
                {`package u0c; type _ interface{int}`, `int`, `int`},
                {`package u1c; type _ interface{~int}`, `~int`, `~int`},
-               {`package u2c; type _ interface{int|string}`, `int | string`, `int|string`},
-               {`package u3c; type _ interface{int|string|~bool}`, `int | string | ~bool`, `int|string|~bool`},
-               {`package u3c; type _ interface{int|string|~bool}`, `int | string`, `int|string`},
-               {`package u3c; type _ interface{int|string|~bool}`, `~bool`, `~bool`},
-               {`package u3c; type _ interface{int|string|~float64|~bool}`, `int | string | ~float64`, `int|string|~float64`},
+               {`package u2c; type _ interface{int | string}`, `int | string`, `int | string`},
+               {`package u3c; type _ interface{int | string | ~bool}`, `int | string | ~bool`, `int | string | ~bool`},
+               {`package u3c; type _ interface{int | string | ~bool}`, `int | string`, `int | string`},
+               {`package u3c; type _ interface{int | string | ~bool}`, `~bool`, `~bool`},
+               {`package u3c; type _ interface{int | string | ~float64|~bool}`, `int | string | ~float64`, `int | string | ~float64`},
        }
 
        for _, test := range tests {
index 43e43ce87c79aeb635c4240f740fe9f641298dca..8e1f290b2b0106f430283e93a5d8f1d3db20da35 100644 (file)
@@ -17,6 +17,9 @@ type termlist []*term
 // It is in normal form.
 var allTermlist = termlist{new(term)}
 
+// termSep is the separator used between individual terms.
+const termSep = " | "
+
 // String prints the termlist exactly (without normalization).
 func (xl termlist) String() string {
        if len(xl) == 0 {
@@ -25,7 +28,7 @@ func (xl termlist) String() string {
        var buf bytes.Buffer
        for i, x := range xl {
                if i > 0 {
-                       buf.WriteString(" | ")
+                       buf.WriteString(termSep)
                }
                buf.WriteString(x.String())
        }
index c10c2d8973916acecaa0295f127fc63cd32c018e..dbee4bf6bc22c38a9889ea028b681965d1d9c1a3 100644 (file)
@@ -191,7 +191,7 @@ func (w *typeWriter) typ(typ Type) {
                }
                for i, t := range t.terms {
                        if i > 0 {
-                               w.byte('|')
+                               w.string(termSep)
                        }
                        if t.tilde {
                                w.byte('~')
index c0689e866c913599a991e10e37bf02b4d655f447..42b1f126f518a1020a9fea683bb7c216dada59e4 100644 (file)
@@ -91,8 +91,8 @@ var independentTestTypes = []testEntry{
        dup("interface{}"),
        dup("interface{m()}"),
        dup(`interface{String() string; m(int) float32}`),
-       dup("interface{int|float32|complex128}"),
-       dup("interface{int|~float32|~complex128}"),
+       dup("interface{int | float32 | complex128}"),
+       dup("interface{int | ~float32 | ~complex128}"),
        dup("any"),
        dup("interface{comparable}"),
        {"comparable", "interface{comparable}"},
index 742ae3d67fa197758f2d2c65e25640b0f759cb5e..8dd30a6ed51de8dff08f3d1208a0ed2039ce6d42 100644 (file)
@@ -358,27 +358,27 @@ func TestTypesInfo(t *testing.T) {
                // issue 50093
                {`package u0a; func _[_ interface{int}]() {}`, `int`, `int`},
                {`package u1a; func _[_ interface{~int}]() {}`, `~int`, `~int`},
-               {`package u2a; func _[_ interface{int|string}]() {}`, `int | string`, `int|string`},
-               {`package u3a; func _[_ interface{int|string|~bool}]() {}`, `int | string | ~bool`, `int|string|~bool`},
-               {`package u3a; func _[_ interface{int|string|~bool}]() {}`, `int | string`, `int|string`},
-               {`package u3a; func _[_ interface{int|string|~bool}]() {}`, `~bool`, `~bool`},
-               {`package u3a; func _[_ interface{int|string|~float64|~bool}]() {}`, `int | string | ~float64`, `int|string|~float64`},
+               {`package u2a; func _[_ interface{int | string}]() {}`, `int | string`, `int | string`},
+               {`package u3a; func _[_ interface{int | string | ~bool}]() {}`, `int | string | ~bool`, `int | string | ~bool`},
+               {`package u3a; func _[_ interface{int | string | ~bool}]() {}`, `int | string`, `int | string`},
+               {`package u3a; func _[_ interface{int | string | ~bool}]() {}`, `~bool`, `~bool`},
+               {`package u3a; func _[_ interface{int | string | ~float64|~bool}]() {}`, `int | string | ~float64`, `int | string | ~float64`},
 
                {`package u0b; func _[_ int]() {}`, `int`, `int`},
                {`package u1b; func _[_ ~int]() {}`, `~int`, `~int`},
-               {`package u2b; func _[_ int|string]() {}`, `int | string`, `int|string`},
-               {`package u3b; func _[_ int|string|~bool]() {}`, `int | string | ~bool`, `int|string|~bool`},
-               {`package u3b; func _[_ int|string|~bool]() {}`, `int | string`, `int|string`},
-               {`package u3b; func _[_ int|string|~bool]() {}`, `~bool`, `~bool`},
-               {`package u3b; func _[_ int|string|~float64|~bool]() {}`, `int | string | ~float64`, `int|string|~float64`},
+               {`package u2b; func _[_ int | string]() {}`, `int | string`, `int | string`},
+               {`package u3b; func _[_ int | string | ~bool]() {}`, `int | string | ~bool`, `int | string | ~bool`},
+               {`package u3b; func _[_ int | string | ~bool]() {}`, `int | string`, `int | string`},
+               {`package u3b; func _[_ int | string | ~bool]() {}`, `~bool`, `~bool`},
+               {`package u3b; func _[_ int | string | ~float64|~bool]() {}`, `int | string | ~float64`, `int | string | ~float64`},
 
                {`package u0c; type _ interface{int}`, `int`, `int`},
                {`package u1c; type _ interface{~int}`, `~int`, `~int`},
-               {`package u2c; type _ interface{int|string}`, `int | string`, `int|string`},
-               {`package u3c; type _ interface{int|string|~bool}`, `int | string | ~bool`, `int|string|~bool`},
-               {`package u3c; type _ interface{int|string|~bool}`, `int | string`, `int|string`},
-               {`package u3c; type _ interface{int|string|~bool}`, `~bool`, `~bool`},
-               {`package u3c; type _ interface{int|string|~float64|~bool}`, `int | string | ~float64`, `int|string|~float64`},
+               {`package u2c; type _ interface{int | string}`, `int | string`, `int | string`},
+               {`package u3c; type _ interface{int | string | ~bool}`, `int | string | ~bool`, `int | string | ~bool`},
+               {`package u3c; type _ interface{int | string | ~bool}`, `int | string`, `int | string`},
+               {`package u3c; type _ interface{int | string | ~bool}`, `~bool`, `~bool`},
+               {`package u3c; type _ interface{int | string | ~float64|~bool}`, `int | string | ~float64`, `int | string | ~float64`},
        }
 
        for _, test := range tests {
index 6d08ddb397aa3539b4f493bf80cd374fd27ebe4b..d65c172ba14e8cce2901cc13fbc74d49417e38cc 100644 (file)
@@ -17,6 +17,9 @@ type termlist []*term
 // It is in normal form.
 var allTermlist = termlist{new(term)}
 
+// termSep is the separator used between individual terms.
+const termSep = " | "
+
 // String prints the termlist exactly (without normalization).
 func (xl termlist) String() string {
        if len(xl) == 0 {
@@ -25,7 +28,7 @@ func (xl termlist) String() string {
        var buf bytes.Buffer
        for i, x := range xl {
                if i > 0 {
-                       buf.WriteString(" | ")
+                       buf.WriteString(termSep)
                }
                buf.WriteString(x.String())
        }
index 5a2e2c171a98ebf953f024db010502f531f341db..080fe2d1f98a5746f815206610c2225a79aa8cd9 100644 (file)
@@ -192,7 +192,7 @@ func (w *typeWriter) typ(typ Type) {
                }
                for i, t := range t.terms {
                        if i > 0 {
-                               w.byte('|')
+                               w.string(termSep)
                        }
                        if t.tilde {
                                w.byte('~')
index b7b843516e1283e66e06c217f5abfc8c737c08b6..d8f81ecf5af5a49eeee5805d51caeb7bd5109711 100644 (file)
@@ -95,8 +95,8 @@ var independentTestTypes = []testEntry{
        dup("interface{}"),
        dup("interface{m()}"),
        dup(`interface{String() string; m(int) float32}`),
-       dup("interface{int|float32|complex128}"),
-       dup("interface{int|~float32|~complex128}"),
+       dup("interface{int | float32 | complex128}"),
+       dup("interface{int | ~float32 | ~complex128}"),
        dup("any"),
        dup("interface{comparable}"),
        // TODO(gri) adjust test for EvalCompositeTest
index a0e2d0c970e50233835113ff55f6c43f9dd40485..d67dfc0f9d17868875f52c59441b5ac6492881e3 100644 (file)
@@ -8,10 +8,10 @@ func f1[T any, C chan T | <-chan T](ch C) {}
 
 func _(ch chan int)   { f1(ch) }
 func _(ch <-chan int) { f1(ch) }
-func _(ch chan<- int) { f1 /* ERROR chan<- int does not implement chan int\|<-chan int */ (ch) }
+func _(ch chan<- int) { f1 /* ERROR chan<- int does not implement chan int \| <-chan int */ (ch) }
 
 func f2[T any, C chan T | chan<- T](ch C) {}
 
 func _(ch chan int)   { f2(ch) }
-func _(ch <-chan int) { f2 /* ERROR <-chan int does not implement chan int\|chan<- int */ (ch) }
+func _(ch <-chan int) { f2 /* ERROR <-chan int does not implement chan int \| chan<- int */ (ch) }
 func _(ch chan<- int) { f2(ch) }
index db5fb32483c3b40617d1f946ae7b9f10fd5fdbe0..12303072edf97deaa90f0d754504e178c2e01b6d 100644 (file)
@@ -19,8 +19,8 @@ func _[P comparable,
         _ = f[R /* ERROR R does not implement comparable */ ]
 
         _ = g[int]
-        _ = g[P /* ERROR P does not implement interface{interface{comparable; ~int\|~string} */ ]
+        _ = g[P /* ERROR P does not implement interface{interface{comparable; ~int \| ~string} */ ]
         _ = g[Q]
-        _ = g[func /* ERROR func\(\) does not implement interface{interface{comparable; ~int\|~string}} */ ()]
-        _ = g[R /* ERROR R does not implement interface{interface{comparable; ~int\|~string} */ ]
+        _ = g[func /* ERROR func\(\) does not implement interface{interface{comparable; ~int \| ~string}} */ ()]
+        _ = g[R /* ERROR R does not implement interface{interface{comparable; ~int \| ~string} */ ]
 }
index 5aa3b82a8d8e447d0cd31448a0f11d5e1f1ec8d6..e9b0adbce989609cf4940bef5ca225e1c4eefb17 100644 (file)
@@ -39,7 +39,7 @@ type C2 interface {
        comparable // ERROR predeclared comparable requires go1\.18 or later
        int        // ERROR embedding non-interface type int requires go1\.18 or later
        ~ /* ERROR embedding interface element ~int requires go1\.18 or later */ int
-       int /* ERROR embedding interface element int\|~string requires go1\.18 or later */ | ~string
+       int /* ERROR embedding interface element int \| ~string requires go1\.18 or later */ | ~string
 }
 
 type _ interface {
index d4c8a897c65a4004a6dacbdc836846aca99b43ca..8890e92f510f5361e905702e0f125acaf9e2b70c 100644 (file)
@@ -13,9 +13,9 @@ type myFloat float64
 
 func _() {
        _ = f1[int]
-       _ = f1[myInt /* ERROR possibly missing ~ for int in constraint int\|string */]
+       _ = f1[myInt /* ERROR possibly missing ~ for int in constraint int \| string */]
        _ = f2[myInt]
-       _ = f2[myFloat /* ERROR possibly missing ~ for float64 in constraint int\|string|float64 */]
+       _ = f2[myFloat /* ERROR possibly missing ~ for float64 in constraint ~int \| string \| float64 */]
        var x myInt
        f3 /* ERROR myInt does not implement int \(possibly missing ~ for int in constraint int\) */ (x)
 }
index 3126770829081668277268c27a974f306af1e59f..ecdc9547fe22361214cdebd9d6c15fde64b8608f 100644 (file)
@@ -49,6 +49,6 @@ func f[T interface{comparable; []byte|string}](x T) {
 }
 
 func _(s []byte) {
-       f /* ERROR \[\]byte does not implement interface{comparable; \[\]byte\|string} */ (s)
+       f /* ERROR \[\]byte does not implement interface{comparable; \[\]byte \| string} */ (s)
         _ = f[[ /* ERROR does not implement */ ]byte]
 }
index 86132428994ee04aa7848fbde2e9f8a832b2027e..f20705c4b2d625ac00138cb91086a05df56561b4 100644 (file)
@@ -109,14 +109,14 @@ func _[X Float, T Float](x X) T    { return T(x) }
 
 func _[X, T Integer | Unsigned | Float](x X) T { return T(x) }
 func _[X, T Integer | ~string](x X) T {
-       return T(x /* ERROR cannot convert x \(variable of type X constrained by Integer\|~string\) to T\n\tcannot convert string \(in X\) to int \(in T\) */)
+       return T(x /* ERROR cannot convert x \(variable of type X constrained by Integer \| ~string\) to T\n\tcannot convert string \(in X\) to int \(in T\) */)
 }
 
 // "x's type and T are both complex types"
 
 func _[X, T Complex](x X) T { return T(x) }
 func _[X, T Float | Complex](x X) T {
-       return T(x /* ERROR cannot convert x \(variable of type X constrained by Float\|Complex\) to T\n\tcannot convert float32 \(in X\) to complex64 \(in T\) */)
+       return T(x /* ERROR cannot convert x \(variable of type X constrained by Float \| Complex\) to T\n\tcannot convert float32 \(in X\) to complex64 \(in T\) */)
 }
 
 // "x is an integer or a slice of bytes or runes and T is a string type"
@@ -138,7 +138,7 @@ func _[X ~[]byte, T ~string](x X) T                     { return T(x) }
 func _[X ~[]rune, T ~string](x X) T                     { return T(x) }
 func _[X Integer | ~[]byte | ~[]rune, T ~string](x X) T { return T(x) }
 func _[X Integer | ~[]byte | ~[]rune, T ~*string](x X) T {
-       return T(x /* ERROR cannot convert x \(variable of type X constrained by Integer\|~\[\]byte\|~\[\]rune\) to T\n\tcannot convert int \(in X\) to \*string \(in T\) */)
+       return T(x /* ERROR cannot convert x \(variable of type X constrained by Integer \| ~\[\]byte \| ~\[\]rune\) to T\n\tcannot convert int \(in X\) to \*string \(in T\) */)
 }
 
 // "x is a string and T is a slice of bytes or runes"