github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/test/fixedbugs/issue4167.go (about)

     1  // run
     2  
     3  // Copyright 2012 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 4167: inlining of a (*T).Method expression taking
     8  // its arguments from a multiple return breaks the compiler.
     9  
    10  package main
    11  
    12  type pa []int
    13  
    14  type p int
    15  
    16  func (this *pa) func1() (v *p, c int) {
    17  	for _ = range *this {
    18  		c++
    19  	}
    20  	v = (*p)(&c)
    21  	return
    22  }
    23  
    24  func (this *pa) func2() p {
    25  	return (*p).func3(this.func1())
    26  }
    27  
    28  func (this *p) func3(f int) p {
    29  	return *this
    30  }
    31  
    32  func (this *pa) func2dots() p {
    33  	return (*p).func3(this.func1())
    34  }
    35  
    36  func (this *p) func3dots(f ...int) p {
    37  	return *this
    38  }
    39  
    40  func main() {
    41  	arr := make(pa, 13)
    42  	length := arr.func2()
    43  	if int(length) != len(arr) {
    44  		panic("length != len(arr)")
    45  	}
    46  	length = arr.func2dots()
    47  	if int(length) != len(arr) {
    48  		panic("length != len(arr)")
    49  	}
    50  }