| 1 |
// run |
| 2 |
|
| 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. |
| 6 |
|
| 7 |
package main |
| 8 |
|
| 9 |
type FooType[T any] interface { |
| 10 |
Foo(BarType[T]) string |
| 11 |
} |
| 12 |
type BarType[T any] interface { |
| 13 |
Bar(FooType[T]) string |
| 14 |
} |
| 15 |
|
| 16 |
// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). |
| 17 |
// type Baz[T any] T |
| 18 |
// func (l Baz[T]) Foo(v BarType[T]) string { |
| 19 |
// return v.Bar(l) |
| 20 |
// } |
| 21 |
// type Bob[T any] T |
| 22 |
// func (l Bob[T]) Bar(v FooType[T]) string { |
| 23 |
// if v,ok := v.(Baz[T]);ok{ |
| 24 |
// return fmt.Sprintf("%v%v",v,l) |
| 25 |
// } |
| 26 |
// return "" |
| 27 |
// } |
| 28 |
|
| 29 |
func main() { |
| 30 |
// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639). |
| 31 |
// var baz Baz[int] = 123 |
| 32 |
// var bob Bob[int] = 456 |
| 33 |
// |
| 34 |
// if got, want := baz.Foo(bob), "123456"; got != want { |
| 35 |
// panic(fmt.Sprintf("got %s want %s", got, want)) |
| 36 |
// } |
| 37 |
} |