From: Robert Griesemer Date: Wed, 10 Nov 2021 05:12:03 +0000 (-0800) Subject: cmd/compile/internal/types2: use type variables consistently in Checker.conversion X-Git-Tag: go1.18beta1~404 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0aa194f7589fb5f75fc3a9c34bb69943daf6fc5c;p=gostls13.git cmd/compile/internal/types2: use type variables consistently in Checker.conversion We have V and T and Vu and Tu. When calling the various isX predicates consistently use Vu and Tu. (We could also use V an T because the predicates call under anyway, but using Vu and Tu removes an unnecessary call to Named.under if V or T are *Named.) Also, removed some outdated comments. Change-Id: I6fcd9ce5f6292e89ac2afd597b72fd0790e84ff1 Reviewed-on: https://go-review.googlesource.com/c/go/+/362895 Trust: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Go Bot Reviewed-by: Robert Findley --- diff --git a/src/cmd/compile/internal/types2/conversions.go b/src/cmd/compile/internal/types2/conversions.go index dd89f29762..7f93e2467f 100644 --- a/src/cmd/compile/internal/types2/conversions.go +++ b/src/cmd/compile/internal/types2/conversions.go @@ -142,39 +142,39 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool { } // "V and T are both integer or floating point types" - if isIntegerOrFloat(V) && isIntegerOrFloat(T) { + if isIntegerOrFloat(Vu) && isIntegerOrFloat(Tu) { return true } // "V and T are both complex types" - if isComplex(V) && isComplex(T) { + if isComplex(Vu) && isComplex(Tu) { return true } // "V is an integer or a slice of bytes or runes and T is a string type" - if (isInteger(V) || isBytesOrRunes(Vu)) && isString(T) { + if (isInteger(Vu) || isBytesOrRunes(Vu)) && isString(Tu) { return true } // "V is a string and T is a slice of bytes or runes" - if isString(V) && isBytesOrRunes(Tu) { + if isString(Vu) && isBytesOrRunes(Tu) { return true } // package unsafe: // "any pointer or value of underlying type uintptr can be converted into a unsafe.Pointer" - if (isPointer(Vu) || isUintptr(Vu)) && isUnsafePointer(T) { + if (isPointer(Vu) || isUintptr(Vu)) && isUnsafePointer(Tu) { return true } // "and vice versa" - if isUnsafePointer(V) && (isPointer(Tu) || isUintptr(Tu)) { + if isUnsafePointer(Vu) && (isPointer(Tu) || isUintptr(Tu)) { return true } // "V a slice, T is a pointer-to-array type, // and the slice and array types have identical element types." - if s, _ := under(V).(*Slice); s != nil { - if p, _ := under(T).(*Pointer); p != nil { + if s, _ := Vu.(*Slice); s != nil { + if p, _ := Tu.(*Pointer); p != nil { if a, _ := under(p.Elem()).(*Array); a != nil { if Identical(s.Elem(), a.Elem()) { if check == nil || check.allowVersion(check.pkg, 1, 17) { @@ -257,20 +257,12 @@ func (x *operand) convertibleTo(check *Checker, T Type, cause *string) bool { return false } -// Helper predicates for convertibleToImpl. The types provided to convertibleToImpl -// may be type parameters but they won't have specific type terms. Thus it is ok to -// use the toT convenience converters in the predicates below. - func isUintptr(typ Type) bool { t, _ := under(typ).(*Basic) return t != nil && t.kind == Uintptr } func isUnsafePointer(typ Type) bool { - // TODO(gri): Is this under(typ).(*Basic) instead of typ.(*Basic) correct? - // (The former calls under(), while the latter doesn't.) - // The spec does not say so, but gc claims it is. See also - // issue 6326. t, _ := under(typ).(*Basic) return t != nil && t.kind == UnsafePointer }