| 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 |
// Make sure we handle instantiated empty interfaces. |
| 8 |
|
| 9 |
package main |
| 10 |
|
| 11 |
type E[T any] interface { |
| 12 |
} |
| 13 |
|
| 14 |
//go:noinline |
| 15 |
func f[T any](x E[T]) interface{} { |
| 16 |
return x |
| 17 |
} |
| 18 |
|
| 19 |
//go:noinline |
| 20 |
func g[T any](x interface{}) E[T] { |
| 21 |
return x |
| 22 |
} |
| 23 |
|
| 24 |
type I[T any] interface { |
| 25 |
foo() |
| 26 |
} |
| 27 |
|
| 28 |
type myint int |
| 29 |
|
| 30 |
func (x myint) foo() {} |
| 31 |
|
| 32 |
//go:noinline |
| 33 |
func h[T any](x I[T]) interface{ foo() } { |
| 34 |
return x |
| 35 |
} |
| 36 |
|
| 37 |
//go:noinline |
| 38 |
func i[T any](x interface{ foo() }) I[T] { |
| 39 |
return x |
| 40 |
} |
| 41 |
|
| 42 |
func main() { |
| 43 |
if f[int](1) != 1 { |
| 44 |
println("test 1 failed") |
| 45 |
} |
| 46 |
if f[int](2) != (interface{})(2) { |
| 47 |
println("test 2 failed") |
| 48 |
} |
| 49 |
if g[int](3) != 3 { |
| 50 |
println("test 3 failed") |
| 51 |
} |
| 52 |
if g[int](4) != (E[int])(4) { |
| 53 |
println("test 4 failed") |
| 54 |
} |
| 55 |
if h[int](myint(5)) != myint(5) { |
| 56 |
println("test 5 failed") |
| 57 |
} |
| 58 |
if h[int](myint(6)) != interface{ foo() }(myint(6)) { |
| 59 |
println("test 6 failed") |
| 60 |
} |
| 61 |
if i[int](myint(7)) != myint(7) { |
| 62 |
println("test 7 failed") |
| 63 |
} |
| 64 |
if i[int](myint(8)) != I[int](myint(8)) { |
| 65 |
println("test 8 failed") |
| 66 |
} |
| 67 |
} |