| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2026 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 Iface[IO any] interface { |
| 10 |
Foo() |
| 11 |
} |
| 12 |
|
| 13 |
type underlyingIfaceImpl struct{} |
| 14 |
|
| 15 |
func (e *underlyingIfaceImpl) Foo() {} |
| 16 |
|
| 17 |
type Impl1[IO any] struct { |
| 18 |
underlyingIfaceImpl |
| 19 |
} |
| 20 |
|
| 21 |
type Impl2 struct { |
| 22 |
underlyingIfaceImpl |
| 23 |
} |
| 24 |
|
| 25 |
func NewImpl1[IO any]() Iface[IO] { |
| 26 |
return &Impl1[IO]{} |
| 27 |
} |
| 28 |
|
| 29 |
var alwaysFalse = false |
| 30 |
|
| 31 |
func main() { |
| 32 |
val := NewImpl1[int]() |
| 33 |
if alwaysFalse { // dead branch |
| 34 |
val = &Impl2{} |
| 35 |
} |
| 36 |
val.Foo() // must not panic |
| 37 |
} |