| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2024 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 |
func main() { |
| 10 |
test1() |
| 11 |
test2() |
| 12 |
} |
| 13 |
|
| 14 |
type I interface { |
| 15 |
f() |
| 16 |
g() |
| 17 |
h() |
| 18 |
} |
| 19 |
|
| 20 |
//go:noinline |
| 21 |
func ld[T any]() { |
| 22 |
var x I |
| 23 |
if _, ok := x.(T); ok { |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
func isI(x any) { |
| 28 |
_ = x.(I) |
| 29 |
} |
| 30 |
|
| 31 |
func test1() { |
| 32 |
defer func() { recover() }() |
| 33 |
ld[bool]() // add <bool,I> itab to binary |
| 34 |
_ = any(false).(I) |
| 35 |
} |
| 36 |
|
| 37 |
type B bool |
| 38 |
|
| 39 |
func (B) f() { |
| 40 |
} |
| 41 |
func (B) g() { |
| 42 |
} |
| 43 |
|
| 44 |
func test2() { |
| 45 |
defer func() { recover() }() |
| 46 |
ld[B]() // add <B,I> itab to binary |
| 47 |
_ = any(B(false)).(I) |
| 48 |
} |