Fixes #72936.
Change-Id: I79ed8d559c8565fa960b974f8c1207ee442f4c26
Reviewed-on: https://go-review.googlesource.com/c/go/+/659256
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
}
// If we have different channel directions, keep the restricted one
// and complain if they conflict.
- if chu.dir == SendRecv {
- ct, cu = t, u // switch to current, possibly restricted channel
- } else if chu.dir != ch.dir {
+ switch {
+ case chu.dir == ch.dir:
+ // nothing to do
+ case chu.dir == SendRecv:
+ ct, cu = t, u // switch to restricted channel
+ case ch.dir != SendRecv:
return bad("channels %s and %s have conflicting directions", ct, t)
-
}
return true
}
}
// If we have different channel directions, keep the restricted one
// and complain if they conflict.
- if chu.dir == SendRecv {
- ct, cu = t, u // switch to current, possibly restricted channel
- } else if chu.dir != ch.dir {
+ switch {
+ case chu.dir == ch.dir:
+ // nothing to do
+ case chu.dir == SendRecv:
+ ct, cu = t, u // switch to restricted channel
+ case ch.dir != SendRecv:
return bad("channels %s and %s have conflicting directions", ct, t)
-
}
return true
}
--- /dev/null
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+func _[C chan<- int | chan int](c C) { c <- 0 }
+func _[C chan int | chan<- int](c C) { c <- 0 }
+func _[C <-chan int | chan<- int](c C) { c <- /* ERROR "receive-only channel <-chan int" */ 0 }
+
+func _[C <-chan int | chan int](c C) { <-c }
+func _[C chan int | <-chan int](c C) { <-c }
+func _[C chan<- int | <-chan int](c C) { <-c /* ERROR "send-only channel chan<- int" */ }
+
+// from issue report
+
+func send[C interface{ ~chan<- V | ~chan V }, V any](c C, v V) {
+ c <- v
+}
+
+func receive[C interface{ ~<-chan V | ~chan V }, V any](c C) V {
+ return <-c
+}