Source file src/internal/types/testdata/fixedbugs/issue49179.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 p 6 7 func f1[P int | string]() {} 8 func f2[P ~int | string | float64]() {} 9 func f3[P int](x P) {} 10 11 type myInt int 12 type myFloat float64 13 14 func _() { 15 _ = f1[int] 16 _ = f1[myInt /* ERROR "possibly missing ~ for int in int | string" */] 17 _ = f2[myInt] 18 _ = f2[myFloat /* ERROR "possibly missing ~ for float64 in ~int | string | float64" */] 19 var x myInt 20 f3 /* ERROR "myInt does not satisfy int (possibly missing ~ for int in int)" */ (x) 21 } 22 23 // test case from the issue 24 25 type SliceConstraint[T any] interface { 26 []T 27 } 28 29 func Map[S SliceConstraint[E], E any](s S, f func(E) E) S { 30 return s 31 } 32 33 type MySlice []int 34 35 func f(s MySlice) { 36 Map[MySlice /* ERROR "MySlice does not satisfy SliceConstraint[int] (possibly missing ~ for []int in SliceConstraint[int])" */, int](s, nil) 37 } 38