1// run -gcflags=-G=3
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
9package main
10
11type E[T any] interface {
12}
13
14//go:noinline
15func f[T any](x E[T]) interface{} {
16	return x
17}
18
19//go:noinline
20func g[T any](x interface{}) E[T] {
21	return x
22}
23
24type I[T any] interface {
25	foo()
26}
27
28type myint int
29
30func (x myint) foo() {}
31
32//go:noinline
33func h[T any](x I[T]) interface{ foo() } {
34	return x
35}
36
37//go:noinline
38func i[T any](x interface{ foo() }) I[T] {
39	return x
40}
41
42func 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}
68