aboutsummaryrefslogtreecommitdiff
path: root/test/typeparam/typelist.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-07-28 13:39:30 -0700
committerMatthew Dempsky <mdempsky@google.com>2021-07-28 21:40:40 +0000
commit53557530093938e19c21f6b02a482939ac6e634b (patch)
tree18d51aa04629aaad621399e997306118b36a5952 /test/typeparam/typelist.go
parent473e493d18c277d69e40a4930af045d474ff2be4 (diff)
downloadgo-53557530093938e19c21f6b02a482939ac6e634b.tar.gz
go-53557530093938e19c21f6b02a482939ac6e634b.zip
[dev.typeparams] test/typeparam: gofmt -w
We don't usually reformat the test directory, but all of the files in test/typeparam are syntactically valid. I suspect the misformattings here are because developers aren't re-installing gofmt with -tags=typeparams, not intentionally exercising non-standard formatting. Change-Id: I3767d480434c19225568f3c7d656dc8589197183 Reviewed-on: https://go-review.googlesource.com/c/go/+/338093 Trust: Matthew Dempsky <mdempsky@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'test/typeparam/typelist.go')
-rw-r--r--test/typeparam/typelist.go30
1 files changed, 17 insertions, 13 deletions
diff --git a/test/typeparam/typelist.go b/test/typeparam/typelist.go
index 5c51c9c461..3d035bf457 100644
--- a/test/typeparam/typelist.go
+++ b/test/typeparam/typelist.go
@@ -10,19 +10,19 @@ package p
// Assignability of an unnamed pointer type to a type parameter that
// has a matching underlying type.
-func _[T interface{}, PT interface{type *T}] (x T) PT {
- return &x
+func _[T interface{}, PT interface{ type *T }](x T) PT {
+ return &x
}
// Indexing of generic types containing type parameters in their type list:
func at[T interface{ type []E }, E any](x T, i int) E {
- return x[i]
+ return x[i]
}
// A generic type inside a function acts like a named type. Its underlying
// type is itself, its "operational type" is defined by the type list in
// the tybe bound, if any.
-func _[T interface{type int}](x T) {
+func _[T interface{ type int }](x T) {
type myint int
var _ int = int(x)
var _ T = 42
@@ -30,7 +30,7 @@ func _[T interface{type int}](x T) {
}
// Indexing a generic type which has a structural contraints to be an array.
-func _[T interface { type [10]int }](x T) {
+func _[T interface{ type [10]int }](x T) {
_ = x[9] // ok
}
@@ -44,7 +44,7 @@ func _[T interface{ type *int }](p T) int {
func _[T interface{ type chan int }](ch T) int {
// This would deadlock if executed (but ok for a compile test)
ch <- 0
- return <- ch
+ return <-ch
}
// Calling of a generic type which has a structural constraint to be a function.
@@ -59,11 +59,10 @@ func _[T interface{ type func(string) int }](f T) int {
}
// Map access of a generic type which has a structural constraint to be a map.
-func _[V any, T interface { type map[string]V }](p T) V {
+func _[V any, T interface{ type map[string]V }](p T) V {
return p["test"]
}
-
// Testing partial and full type inference, including the case where the types can
// be inferred without needing the types of the function arguments.
@@ -86,7 +85,7 @@ func _() {
}
*/
-func f2[A any, B interface{type []A}](_ A, _ B)
+func f2[A any, B interface{ type []A }](_ A, _ B)
func _() {
f := f2[byte]
f(byte(0), []byte{})
@@ -106,7 +105,7 @@ func _() {
}
*/
-func f4[A any, B interface{type []C}, C interface{type *A}](_ A, _ B, c C)
+func f4[A any, B interface{ type []C }, C interface{ type *A }](_ A, _ B, c C)
func _() {
f := f4[int]
var x int
@@ -114,15 +113,20 @@ func _() {
f4(x, []*int{}, &x)
}
-func f5[A interface{type struct{b B; c C}}, B any, C interface{type *B}](x B) A
+func f5[A interface {
+ type struct {
+ b B
+ c C
+ }
+}, B any, C interface{ type *B }](x B) A
func _() {
x := f5(1.2)
var _ float64 = x.b
var _ float64 = *x.c
}
-func f6[A any, B interface{type struct{f []A}}](B) A
+func f6[A any, B interface{ type struct{ f []A } }](B) A
func _() {
- x := f6(struct{f []string}{})
+ x := f6(struct{ f []string }{})
var _ string = x
}