| 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 |
// Zero returns the zero value of T |
| 10 |
func Zero[T any]() (_ T) { |
| 11 |
return |
| 12 |
} |
| 13 |
|
| 14 |
type AnyInt[X any] int |
| 15 |
|
| 16 |
func (AnyInt[X]) M() { |
| 17 |
var have interface{} = Zero[X]() |
| 18 |
var want interface{} = Zero[MyInt]() |
| 19 |
|
| 20 |
if have != want { |
| 21 |
println("FAIL") |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
type I interface{ M() } |
| 26 |
|
| 27 |
type MyInt int |
| 28 |
type U = AnyInt[MyInt] |
| 29 |
|
| 30 |
var x = U(0) |
| 31 |
var i I = x |
| 32 |
|
| 33 |
func main() { |
| 34 |
x.M() |
| 35 |
U.M(x) |
| 36 |
(*U).M(&x) |
| 37 |
|
| 38 |
i.M() |
| 39 |
I.M(x) |
| 40 |
} |