Source file src/internal/types/testdata/fixedbugs/issue40789.go

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import "fmt"
     8  
     9  func main() {
    10  	m := map[string]int{
    11  		"a": 6,
    12  		"b": 7,
    13  	}
    14  	fmt.Println(copyMap[map[string]int, string, int](m))
    15  }
    16  
    17  type Map[K comparable, V any] interface {
    18  	map[K] V
    19  }
    20  
    21  func copyMap[M Map[K, V], K comparable, V any](m M) M {
    22  	m1 := make(M)
    23  	for k, v := range m {
    24  		m1[k] = v
    25  	}
    26  	return m1
    27  }
    28  
    29  // simpler test case from the same issue
    30  
    31  type A[X comparable] interface {
    32  	[]X
    33  }
    34  
    35  func f[B A[X], X comparable]() B {
    36  	return nil
    37  }
    38  

View as plain text