From: Robert Findley Date: Tue, 16 Nov 2021 03:22:26 +0000 (-0500) Subject: go/types: use type variables consistently in Checker.conversion X-Git-Tag: go1.18beta1~300 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bddb79f0faa11958ff473109398be684c088a6a9;p=gostls13.git go/types: use type variables consistently in Checker.conversion This is a clean port of CL 362895 from types2 to go/types. Change-Id: Icd0631127c51aec80ce9450df2be71bf4b96b2df Reviewed-on: https://go-review.googlesource.com/c/go/+/363987 Trust: Robert Findley Run-TryBot: Robert Findley TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- diff --git a/src/go/types/conversions.go b/src/go/types/conversions.go index 26bebd4ade..18d24e404c 100644 --- a/src/go/types/conversions.go +++ b/src/go/types/conversions.go @@ -139,39 +139,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 is a slice, T is a pointer-to-array type, + // "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) { @@ -249,20 +249,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 }