Source file test/tailcall.go

     1  // errorcheck -0 -d=tailcall=1
     2  
     3  // Copyright 2024 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  package p
     8  
     9  // Test that when generating wrappers for methods, we generate a tail call to the pointer version of
    10  // the method, if that method is not inlineable. We use go:noinline here to force the non-inlineability
    11  // condition.
    12  
    13  //go:noinline
    14  func (f *Foo) Get2Vals() [2]int { return [2]int{f.Val, f.Val + 1} }
    15  func (f *Foo) Get3Vals() [3]int { return [3]int{f.Val, f.Val + 1, f.Val + 2} }
    16  
    17  type Foo struct{ Val int }
    18  
    19  type Bar struct { // ERROR "tail call emitted for the method \(\*Foo\).Get2Vals wrapper"
    20  	int64
    21  	*Foo // needs a method wrapper
    22  	string
    23  }
    24  
    25  var i any
    26  
    27  func init() {
    28  	i = Bar{1, nil, "first"}
    29  }
    30  

View as plain text