Source file test/typeparam/issue48598.go

     1  // run
     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 Iterator[T any] interface {
    10  	Iterate()
    11  }
    12  
    13  type IteratorFunc[T any] func(fn func(T) bool)
    14  
    15  func (f IteratorFunc[T]) Iterate() {
    16  }
    17  
    18  func FromIterator[T any](it Iterator[T]) {
    19  	it.Iterate()
    20  }
    21  
    22  func Foo[T, R any]() {
    23  	FromIterator[R](IteratorFunc[R](nil))
    24  }
    25  
    26  func main() {
    27  	Foo[int, int]()
    28  }
    29  

View as plain text