1// compile 2 3// Copyright 2020 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 7package p 8 9type I struct { 10 x int64 11} 12 13type F struct { 14 x float64 15} 16 17type C struct { 18 x *complex128 19} 20 21type D struct { 22 x complex64 23} 24 25type A [1]*complex128 26 27//go:noinline 28func (i I) X() C { 29 cx := complex(0, float64(i.x)) 30 return C{&cx} 31} 32 33//go:noinline 34func (f F) X() C { 35 cx := complex(f.x, 0) 36 return C{&cx} 37} 38 39//go:noinline 40func (c C) X() C { 41 cx := complex(imag(*c.x), real(*c.x)) 42 return C{&cx} 43} 44 45//go:noinline 46func (d D) X() C { 47 cx := complex(float64(imag(d.x)), -float64(real(d.x))) 48 return C{&cx} 49} 50 51//go:noinline 52func (a A) X() C { 53 cx := complex(-float64(imag(*a[0])), float64(real(*a[0]))) 54 return C{&cx} 55} 56 57//go:noinline 58func (i I) id() I { 59 return i 60} 61 62//go:noinline 63func (f F) id() F { 64 return f 65} 66 67//go:noinline 68func (c C) id() C { 69 return c 70} 71 72//go:noinline 73func (d D) id() D { 74 return d 75} 76 77//go:noinline 78func (a A) id() A { 79 return a 80} 81 82type T interface { 83 X() C 84} 85 86func G(x []T) []T { 87 var y []T 88 for _, a := range x { 89 var v T 90 switch u := a.(type) { 91 case I: 92 v = u.id() 93 case F: 94 v = u.id() 95 case C: 96 v = u.id() 97 case D: 98 v = u.id() 99 case A: 100 v = u.id() 101 } 102 y = append(y, v) 103 } 104 return y 105} 106