github.com/huandu/go@v0.0.0-20151114150818-04e615e41150/test/fixedbugs/bug401.go (about)

     1  // run
     2  
     3  // Copyright 2011 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  // Issue 2582
     8  package main
     9  
    10  type T struct{}
    11  
    12  func (T) cplx() complex128 {
    13  	for false {
    14  	} // avoid inlining
    15  	return complex(1, 0)
    16  }
    17  
    18  func (T) cplx2() complex128 {
    19  	return complex(0, 1)
    20  }
    21  
    22  type I interface {
    23  	cplx() complex128
    24  }
    25  
    26  func main() {
    27  
    28  	var t T
    29  
    30  	if v := real(t.cplx()); v != 1 {
    31  		panic("not-inlined complex call failed")
    32  	}
    33  	_ = imag(t.cplx())
    34  
    35  	_ = real(t.cplx2())
    36  	if v := imag(t.cplx2()); v != 1 {
    37  		panic("potentially inlined complex call failed")
    38  	}
    39  
    40  	var i I
    41  	i = t
    42  	if v := real(i.cplx()); v != 1 {
    43  		panic("potentially inlined complex call failed")
    44  	}
    45  	_ = imag(i.cplx())
    46  }