From: Robert Griesemer Date: Thu, 27 Jan 2022 20:53:13 +0000 (-0800) Subject: go/types, types2: remove Qualifier parameter from Checker.implements X-Git-Tag: go1.18beta2~6 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8f7d96f5bcb927a576a43b890f2643e521107665;p=gostls13.git go/types, types2: remove Qualifier parameter from Checker.implements Where we provide it we take it from the Checker (which is already passed in). Thus there's no need to pass it separately. Cleanup. Change-Id: I63ae445ccac5643235d85e1867462ef5c01ad5fe Reviewed-on: https://go-review.googlesource.com/c/go/+/381297 Trust: Robert Griesemer Reviewed-by: Robert Findley --- diff --git a/src/cmd/compile/internal/types2/api.go b/src/cmd/compile/internal/types2/api.go index fe754db7a4..ee4f275bc0 100644 --- a/src/cmd/compile/internal/types2/api.go +++ b/src/cmd/compile/internal/types2/api.go @@ -450,7 +450,7 @@ func Implements(V Type, T *Interface) bool { if V.Underlying() == Typ[Invalid] { return false } - return (*Checker)(nil).implements(V, T, nil) == nil + return (*Checker)(nil).implements(V, T) == nil } // Identical reports whether x and y are identical types. diff --git a/src/cmd/compile/internal/types2/instantiate.go b/src/cmd/compile/internal/types2/instantiate.go index e8f2d98d25..81a3cdeb0b 100644 --- a/src/cmd/compile/internal/types2/instantiate.go +++ b/src/cmd/compile/internal/types2/instantiate.go @@ -133,14 +133,6 @@ func (check *Checker) validateTArgLen(pos syntax.Pos, ntparams, ntargs int) bool } func (check *Checker) verify(pos syntax.Pos, tparams []*TypeParam, targs []Type) (int, error) { - // TODO(rfindley): it would be great if users could pass in a qualifier here, - // rather than falling back to verbose qualification. Maybe this can be part - // of the shared context. - var qf Qualifier - if check != nil { - qf = check.qualifier - } - smap := makeSubstMap(tparams, targs) for i, tpar := range tparams { // The type parameter bound is parameterized with the same type parameters @@ -148,7 +140,7 @@ func (check *Checker) verify(pos syntax.Pos, tparams []*TypeParam, targs []Type) // need to instantiate it with the type arguments with which we instantiated // the parameterized type. bound := check.subst(pos, tpar.bound, smap, nil) - if err := check.implements(targs[i], bound, qf); err != nil { + if err := check.implements(targs[i], bound); err != nil { return i, err } } @@ -156,10 +148,9 @@ func (check *Checker) verify(pos syntax.Pos, tparams []*TypeParam, targs []Type) } // implements checks if V implements T and reports an error if it doesn't. -// If a qualifier is provided, it is used in error formatting. // The receiver may be nil if implements is called through an exported // API call such as AssignableTo. -func (check *Checker) implements(V, T Type, qf Qualifier) error { +func (check *Checker) implements(V, T Type) error { Vu := under(V) Tu := under(T) if Vu == Typ[Invalid] || Tu == Typ[Invalid] { @@ -169,6 +160,10 @@ func (check *Checker) implements(V, T Type, qf Qualifier) error { return nil // avoid follow-on errors (see issue #49541 for an example) } + var qf Qualifier + if check != nil { + qf = check.qualifier + } errorf := func(format string, args ...interface{}) error { return errors.New(sprintf(qf, false, format, args...)) } diff --git a/src/cmd/compile/internal/types2/operand.go b/src/cmd/compile/internal/types2/operand.go index 1bda0a51f5..fce9a11ffa 100644 --- a/src/cmd/compile/internal/types2/operand.go +++ b/src/cmd/compile/internal/types2/operand.go @@ -291,11 +291,7 @@ func (x *operand) assignableTo(check *Checker, T Type, reason *string) (bool, er // T is an interface type and x implements T and T is not a type parameter. // Also handle the case where T is a pointer to an interface. if _, ok := Tu.(*Interface); ok && Tp == nil || isInterfacePtr(Tu) { - var qf Qualifier - if check != nil { - qf = check.qualifier - } - if err := check.implements(V, T, qf); err != nil { + if err := check.implements(V, T); err != nil { if reason != nil { *reason = err.Error() } @@ -306,7 +302,7 @@ func (x *operand) assignableTo(check *Checker, T Type, reason *string) (bool, er // If V is an interface, check if a missing type assertion is the problem. if Vi, _ := Vu.(*Interface); Vi != nil && Vp == nil { - if check.implements(T, V, nil) == nil { + if check.implements(T, V) == nil { // T implements V, so give hint about type assertion. if reason != nil { *reason = "need type assertion" diff --git a/src/go/types/api.go b/src/go/types/api.go index a2cc289fbc..2776e05232 100644 --- a/src/go/types/api.go +++ b/src/go/types/api.go @@ -446,7 +446,7 @@ func Implements(V Type, T *Interface) bool { if V.Underlying() == Typ[Invalid] { return false } - return (*Checker)(nil).implements(V, T, nil) == nil + return (*Checker)(nil).implements(V, T) == nil } // Identical reports whether x and y are identical types. diff --git a/src/go/types/instantiate.go b/src/go/types/instantiate.go index 4a167eb91e..09a841bb98 100644 --- a/src/go/types/instantiate.go +++ b/src/go/types/instantiate.go @@ -133,14 +133,6 @@ func (check *Checker) validateTArgLen(pos token.Pos, ntparams, ntargs int) bool } func (check *Checker) verify(pos token.Pos, tparams []*TypeParam, targs []Type) (int, error) { - // TODO(rfindley): it would be great if users could pass in a qualifier here, - // rather than falling back to verbose qualification. Maybe this can be part - // of the shared context. - var qf Qualifier - if check != nil { - qf = check.qualifier - } - smap := makeSubstMap(tparams, targs) for i, tpar := range tparams { // The type parameter bound is parameterized with the same type parameters @@ -148,7 +140,7 @@ func (check *Checker) verify(pos token.Pos, tparams []*TypeParam, targs []Type) // need to instantiate it with the type arguments with which we instantiated // the parameterized type. bound := check.subst(pos, tpar.bound, smap, nil) - if err := check.implements(targs[i], bound, qf); err != nil { + if err := check.implements(targs[i], bound); err != nil { return i, err } } @@ -156,10 +148,9 @@ func (check *Checker) verify(pos token.Pos, tparams []*TypeParam, targs []Type) } // implements checks if V implements T and reports an error if it doesn't. -// If a qualifier is provided, it is used in error formatting. // The receiver may be nil if implements is called through an exported // API call such as AssignableTo. -func (check *Checker) implements(V, T Type, qf Qualifier) error { +func (check *Checker) implements(V, T Type) error { Vu := under(V) Tu := under(T) if Vu == Typ[Invalid] || Tu == Typ[Invalid] { @@ -169,6 +160,10 @@ func (check *Checker) implements(V, T Type, qf Qualifier) error { return nil // avoid follow-on errors (see issue #49541 for an example) } + var qf Qualifier + if check != nil { + qf = check.qualifier + } errorf := func(format string, args ...any) error { return errors.New(sprintf(nil, qf, false, format, args...)) } diff --git a/src/go/types/operand.go b/src/go/types/operand.go index c04c5742a8..4d7f1e3b63 100644 --- a/src/go/types/operand.go +++ b/src/go/types/operand.go @@ -280,11 +280,7 @@ func (x *operand) assignableTo(check *Checker, T Type, reason *string) (bool, er // T is an interface type and x implements T and T is not a type parameter. // Also handle the case where T is a pointer to an interface. if _, ok := Tu.(*Interface); ok && Tp == nil || isInterfacePtr(Tu) { - var qf Qualifier - if check != nil { - qf = check.qualifier - } - if err := check.implements(V, T, qf); err != nil { + if err := check.implements(V, T); err != nil { if reason != nil { *reason = err.Error() } @@ -295,7 +291,7 @@ func (x *operand) assignableTo(check *Checker, T Type, reason *string) (bool, er // If V is an interface, check if a missing type assertion is the problem. if Vi, _ := Vu.(*Interface); Vi != nil && Vp == nil { - if check.implements(T, V, nil) == nil { + if check.implements(T, V) == nil { // T implements V, so give hint about type assertion. if reason != nil { *reason = "need type assertion"