mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
go/types: minor simplification in assignableTo (cleanup)
Also, clarify doc string. Change-Id: If1c5f8e29e2c2080dd899ef76196e97b7b992389 Reviewed-on: https://go-review.googlesource.com/c/go/+/302758 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
f47fab938e
commit
b95e4b7850
1 changed files with 5 additions and 8 deletions
|
|
@ -222,9 +222,10 @@ func (x *operand) isNil() bool {
|
||||||
|
|
||||||
// assignableTo reports whether x is assignable to a variable of type T. If the
|
// assignableTo reports whether x is assignable to a variable of type T. If the
|
||||||
// result is false and a non-nil reason is provided, it may be set to a more
|
// result is false and a non-nil reason is provided, it may be set to a more
|
||||||
// detailed explanation of the failure (result != ""). The check parameter may
|
// detailed explanation of the failure (result != ""). The returned error code
|
||||||
// be nil if assignableTo is invoked through an exported API call, i.e., when
|
// is only valid if the (first) result is false. The check parameter may be nil
|
||||||
// all methods have been type-checked.
|
// if assignableTo is invoked through an exported API call, i.e., when all
|
||||||
|
// methods have been type-checked.
|
||||||
func (x *operand) assignableTo(check *Checker, T Type, reason *string) (bool, errorCode) {
|
func (x *operand) assignableTo(check *Checker, T Type, reason *string) (bool, errorCode) {
|
||||||
if x.mode == invalid || T == Typ[Invalid] {
|
if x.mode == invalid || T == Typ[Invalid] {
|
||||||
return true, 0 // avoid spurious errors
|
return true, 0 // avoid spurious errors
|
||||||
|
|
@ -285,11 +286,7 @@ func (x *operand) assignableTo(check *Checker, T Type, reason *string) (bool, er
|
||||||
// and at least one of V or T is not a named type
|
// and at least one of V or T is not a named type
|
||||||
if Vc, ok := Vu.(*Chan); ok && Vc.dir == SendRecv {
|
if Vc, ok := Vu.(*Chan); ok && Vc.dir == SendRecv {
|
||||||
if Tc, ok := Tu.(*Chan); ok && check.identical(Vc.elem, Tc.elem) {
|
if Tc, ok := Tu.(*Chan); ok && check.identical(Vc.elem, Tc.elem) {
|
||||||
if !isNamed(V) || !isNamed(T) {
|
return !isNamed(V) || !isNamed(T), _InvalidChanAssign
|
||||||
return true, 0
|
|
||||||
} else {
|
|
||||||
return false, _InvalidChanAssign
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue