github.com/JimmyHuang454/JLS-go@v0.0.0-20230831150107-90d536585ba0/internal/types/testdata/fixedbugs/issue43671.go (about) 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 type C0 interface{ int } 8 type C1 interface{ chan int } 9 type C2 interface{ chan int | <-chan int } 10 type C3 interface{ chan int | chan float32 } 11 type C4 interface{ chan int | chan<- int } 12 type C5[T any] interface{ ~chan T | <-chan T } 13 14 func _[T any](ch T) { 15 <-ch // ERROR cannot receive from ch .* \(no core type\) 16 } 17 18 func _[T C0](ch T) { 19 <-ch // ERROR cannot receive from non-channel ch 20 } 21 22 func _[T C1](ch T) { 23 <-ch 24 } 25 26 func _[T C2](ch T) { 27 <-ch 28 } 29 30 func _[T C3](ch T) { 31 <-ch // ERROR cannot receive from ch .* \(no core type\) 32 } 33 34 func _[T C4](ch T) { 35 <-ch // ERROR cannot receive from send-only channel 36 } 37 38 func _[T C5[X], X any](ch T, x X) { 39 x = <-ch 40 } 41 42 // test case from issue, slightly modified 43 type RecvChan[T any] interface { 44 ~chan T | ~<-chan T 45 } 46 47 func _[T any, C RecvChan[T]](ch C) T { 48 return <-ch 49 } 50 51 func f[T any, C interface{ chan T }](ch C) T { 52 return <-ch 53 } 54 55 func _(ch chan int) { 56 var x int = f(ch) // test constraint type inference for this case 57 _ = x 58 }