Source file test/typeparam/issue58513.go

     1  // run
     2  
     3  // Copyright 2023 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  // Some derived-type expressions require the compiler to synthesize
     8  // function literals to plumb sub-dictionaries appropriately.
     9  // However, when these expressions are inlined, we were constructing
    10  // the function literal bodies with the inline-adjusted positions
    11  // instead of the original (inline-free) positions, which could lead
    12  // to infinite loops when unwinding the stack.
    13  
    14  package main
    15  
    16  import "runtime"
    17  
    18  func assert[_ any]() {
    19  	panic(0)
    20  }
    21  
    22  func Assert[To any]() func() {
    23  	return assert[To]
    24  }
    25  
    26  type asserter[_ any] struct{}
    27  
    28  func (asserter[_]) assert() {
    29  	panic(0)
    30  }
    31  
    32  func AssertMV[To any]() func() {
    33  	return asserter[To]{}.assert
    34  }
    35  
    36  func AssertME[To any]() func(asserter[To]) {
    37  	return asserter[To].assert
    38  }
    39  
    40  var me = AssertME[string]()
    41  
    42  var tests = []func(){
    43  	Assert[int](),
    44  	AssertMV[int](),
    45  	func() { me(asserter[string]{}) },
    46  }
    47  
    48  func main() {
    49  	for _, test := range tests {
    50  		func() {
    51  			defer func() {
    52  				recover()
    53  
    54  				// Check that we can unwind the stack without infinite looping.
    55  				runtime.Caller(1000)
    56  			}()
    57  			test()
    58  		}()
    59  	}
    60  }
    61  

View as plain text