mirror of
https://github.com/golang/go
synced 2024-11-23 21:20:03 -07:00
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 <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
25b4b862f2
commit
8f7d96f5bc
@ -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.
|
||||
|
@ -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...))
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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.
|
||||
|
@ -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...))
|
||||
}
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user