Source file test/typeparam/issue47878.go

     1  // compile
     2  
     3  // Copyright 2021 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 main
     8  
     9  type Src1[T any] func() Src1[T]
    10  
    11  func (s *Src1[T]) Next() {
    12  	*s = (*s)()
    13  }
    14  
    15  type Src2[T any] []func() Src2[T]
    16  
    17  func (s Src2[T]) Next() {
    18  	_ = s[0]()
    19  }
    20  
    21  type Src3[T comparable] map[T]func() Src3[T]
    22  
    23  func (s Src3[T]) Next() {
    24  	var a T
    25  	_ = s[a]()
    26  }
    27  
    28  type Src4[T any] chan func() T
    29  
    30  func (s Src4[T]) Next() {
    31  	_ = (<-s)()
    32  }
    33  
    34  type Src5[T any] func() Src5[T]
    35  
    36  func (s Src5[T]) Next() {
    37  	var x interface{} = s
    38  	_ = (x.(Src5[T]))()
    39  }
    40  
    41  func main() {
    42  	var src1 Src1[int]
    43  	src1.Next()
    44  
    45  	var src2 Src2[int]
    46  	src2.Next()
    47  
    48  	var src3 Src3[string]
    49  	src3.Next()
    50  
    51  	var src4 Src4[int]
    52  	src4.Next()
    53  
    54  	var src5 Src5[int]
    55  	src5.Next()
    56  }
    57  

View as plain text