diff options
Diffstat (limited to 'test/typeparam')
| -rw-r--r-- | test/typeparam/issue47676.go | 23 | ||||
| -rw-r--r-- | test/typeparam/issue48016.go | 35 | ||||
| -rw-r--r-- | test/typeparam/typeswitch2.go | 4 |
3 files changed, 60 insertions, 2 deletions
diff --git a/test/typeparam/issue47676.go b/test/typeparam/issue47676.go new file mode 100644 index 0000000000..1b01624ce0 --- /dev/null +++ b/test/typeparam/issue47676.go @@ -0,0 +1,23 @@ +// run -gcflags=-G=3 + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +func main() { + d := diff([]int{}, func(int) string { + return "foo" + }) + d() +} + +func diff[T any](previous []T, uniqueKey func(T) string) func() { + return func() { + newJSON := map[string]T{} + for _, prev := range previous { + delete(newJSON, uniqueKey(prev)) + } + } +} diff --git a/test/typeparam/issue48016.go b/test/typeparam/issue48016.go new file mode 100644 index 0000000000..582751e884 --- /dev/null +++ b/test/typeparam/issue48016.go @@ -0,0 +1,35 @@ +// run -gcflags=-G=3 + +// Copyright 2021 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +import ( + "fmt" + "strconv" +) + +func test1[T any](fn func(T) int, v T) int { + fn1 := func() int { + var i interface{} = v + val := fn(i.(T)) + return val + } + return fn1() +} + +func main() { + want := 123 + got := test1(func(s string) int { + r, err := strconv.Atoi(s) + if err != nil { + return 0 + } + return r + }, "123") + if got != want { + panic(fmt.Sprintf("got %f, want %f", got, want)) + } +} diff --git a/test/typeparam/typeswitch2.go b/test/typeparam/typeswitch2.go index 913c56321c..0e434e1383 100644 --- a/test/typeparam/typeswitch2.go +++ b/test/typeparam/typeswitch2.go @@ -16,7 +16,7 @@ func f[T any](i interface{}) { println("int", x) case int32, int16: println("int32/int16", reflect.ValueOf(x).Int()) - case struct { a, b T }: + case struct{ a, b T }: println("struct{T,T}", x.a, x.b) default: println("other", reflect.ValueOf(x).Int()) @@ -26,6 +26,6 @@ func main() { f[float64](float64(6)) f[float64](int(7)) f[float64](int32(8)) - f[float64](struct{a, b float64}{a:1, b:2}) + f[float64](struct{ a, b float64 }{a: 1, b: 2}) f[float64](int8(9)) } |
