mirror of https://github.com/golang/go.git
go/types, types2: fix silly logic error in commonUnder
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>
This commit is contained in:
parent
1aa9c31ffc
commit
011b7ce8d1
|
|
@ -112,11 +112,13 @@ func commonUnder(t Type, cond func(t, u Type) *typeError) (Type, *typeError) {
|
|||
}
|
||||
// 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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,11 +115,13 @@ func commonUnder(t Type, cond func(t, u Type) *typeError) (Type, *typeError) {
|
|||
}
|
||||
// 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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
// 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
|
||||
}
|
||||
Loading…
Reference in New Issue