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.
}
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
// 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
}
}
}
// 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] {
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...))
}
// 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()
}
// 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"
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.
}
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
// 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
}
}
}
// 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] {
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...))
}
// 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()
}
// 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"