blob: 215498e085707eba846f6af3594d10608b85636f [file] [log] [blame]
Rémy Oudompheng2ece2f52012-02-18 22:15:42 +01001// run
Luuk van Dijk5ad9e2d2012-01-23 16:56:57 +01002
Emmanuel Odeke53fd5222016-04-10 14:32:26 -07003// Copyright 2011 The Go Authors. All rights reserved.
Luuk van Dijk5ad9e2d2012-01-23 16:56:57 +01004// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7// Issue 2582
Russ Coxee9bfb02012-01-25 17:53:50 -05008package main
9
10type T struct{}
11
Todd Neale3e01222015-10-29 21:45:19 -050012//go:noinline
Luuk van Dijk5ad9e2d2012-01-23 16:56:57 +010013func (T) cplx() complex128 {
Russ Coxee9bfb02012-01-25 17:53:50 -050014 return complex(1, 0)
15}
16
17func (T) cplx2() complex128 {
18 return complex(0, 1)
Luuk van Dijk5ad9e2d2012-01-23 16:56:57 +010019}
20
21type I interface {
22 cplx() complex128
23}
24
Russ Coxee9bfb02012-01-25 17:53:50 -050025func main() {
Luuk van Dijk5ad9e2d2012-01-23 16:56:57 +010026
Russ Coxee9bfb02012-01-25 17:53:50 -050027 var t T
28
29 if v := real(t.cplx()); v != 1 {
30 panic("not-inlined complex call failed")
31 }
32 _ = imag(t.cplx())
33
34 _ = real(t.cplx2())
35 if v := imag(t.cplx2()); v != 1 {
36 panic("potentially inlined complex call failed")
37 }
Luuk van Dijk5ad9e2d2012-01-23 16:56:57 +010038
39 var i I
40 i = t
Russ Coxee9bfb02012-01-25 17:53:50 -050041 if v := real(i.cplx()); v != 1 {
42 panic("potentially inlined complex call failed")
43 }
44 _ = imag(i.cplx())
45}