Debian Codegraph @

test/typeparam/issue47925c.go

raw
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 package main
8
9 type I[T any] interface {
10 foo()
11 }
12
13 type J[T any] interface {
14 foo()
15 bar()
16 }
17
18 //go:noinline
19 func f[T J[T]](x T) I[T] {
20 // contains a cast between two nonempty interfaces
21 return I[T](J[T](x))
22 }
23
24 type S struct {
25 x int
26 }
27
28 func (s *S) foo() {}
29 func (s *S) bar() {}
30
31 func main() {
32 i := f(&S{x: 7})
33 if i.(*S).x != 7 {
34 panic("bad")
35 }
36 }