modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue5056.go (about)

     1  // run
     2  
     3  // Copyright 2013 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 5056: escape analysis not applied to wrapper functions
     8  
     9  package main
    10  
    11  type Foo int16
    12  
    13  func (f Foo) Esc() *int{
    14  	x := int(f)
    15  	return &x
    16  }
    17  
    18  type iface interface {
    19  	Esc() *int
    20  }
    21  
    22  var bar, foobar *int
    23  
    24  func main() {
    25  	var quux iface
    26  	var x Foo
    27  	
    28  	quux = x
    29  	bar = quux.Esc()
    30  	foobar = quux.Esc()
    31  	if bar == foobar {
    32  		panic("bar == foobar")
    33  	}
    34  }