3 // Copyright 2021 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
11 type Fn[T any] func(T)
12 type FnErr[T any] func(T) error
14 // Test that local generic types across functions don't conflict, and they also don't
15 // conflict with local non-generic types and local variables.
17 type X[T any] struct {
21 x := X[int]{func(v int) { fmt.Println(v) }}
25 func caller1(val int) {
26 type X[T any] struct {
30 x := X[int]{func(v int) error { fmt.Println(v); return nil }}
34 func caller1a(val int) {
36 fn func(float64) error
39 x := X{func(v float64) error { fmt.Println(v); return nil }}
43 func caller1b(val int) {
45 fn func(float64) error
48 X := Y{func(v float64) error { fmt.Println(v); return nil }}
52 // Test that local generic types within different if clauses don't conflict.
53 func caller2(val int) {
55 type X[T any] struct {
56 fn func(v int) float64
59 x := X[int]{func(v int) float64 { fmt.Println(v); return 1.5 }}
62 type X[T any] struct {
65 x := X[int]{func(v int) int { fmt.Println(v); return 5 }}
70 // Test that local generic types within different cases don't conflict with each
71 // other or with local non-generic types or local variables.
72 func caller3(val int) {
75 type X[T any] struct {
76 fn func(v int) float64
79 x := X[int]{func(v int) float64 { fmt.Println(v); return 1.5 }}
82 type X[T any] struct {
85 x := X[int]{func(v int) int { fmt.Println(v); return 5 }}
91 x := X{func(v int) bool { fmt.Println(v); return false }}
97 X := Y{func(v int) bool { fmt.Println(v); return false }}