| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2022 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 SomeInterface interface { |
| 10 |
Whatever() |
| 11 |
} |
| 12 |
|
| 13 |
func X[T any]() T { |
| 14 |
var m T |
| 15 |
|
| 16 |
// for this example, this block should never run |
| 17 |
if _, ok := any(m).(SomeInterface); ok { |
| 18 |
var dst SomeInterface |
| 19 |
_, _ = dst.(T) |
| 20 |
return dst.(T) |
| 21 |
} |
| 22 |
|
| 23 |
return m |
| 24 |
} |
| 25 |
|
| 26 |
type holder struct{} |
| 27 |
|
| 28 |
func main() { |
| 29 |
X[holder]() |
| 30 |
} |