]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types, types2: remove Qualifier parameter from Checker.implements
authorRobert Griesemer <gri@golang.org>
Thu, 27 Jan 2022 20:53:13 +0000 (12:53 -0800)
committerRobert Griesemer <gri@golang.org>
Fri, 28 Jan 2022 22:21:51 +0000 (22:21 +0000)
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>
src/cmd/compile/internal/types2/api.go
src/cmd/compile/internal/types2/instantiate.go
src/cmd/compile/internal/types2/operand.go
src/go/types/api.go
src/go/types/instantiate.go
src/go/types/operand.go

index fe754db7a4e337d0df9454f3a14ba25b1892f454..ee4f275bc072ff7bc5f1dd3928d98571068cc56d 100644 (file)
@@ -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.
index e8f2d98d25f24ae25691c323803fd9c097ae1f08..81a3cdeb0ba645d8108bbd010a654e73e4c2db02 100644 (file)
@@ -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...))
        }
index 1bda0a51f5aeada520daf2603e57685b750dbb6a..fce9a11ffa2f5a85474b737d5835db92ebb64087 100644 (file)
@@ -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"
index a2cc289fbce455d65a9140e0797e8403bc202047..2776e05232c87e75ede4da800be64258617515ef 100644 (file)
@@ -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.
index 4a167eb91e09c6c888489a75891182adb78695b1..09a841bb98c7770f614f460a2fbb78bd3dfeed49 100644 (file)
@@ -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...))
        }
index c04c5742a85b1e1fac254a562288fb410bfef9de..4d7f1e3b63f274b6ce30aefa010f1037f104e6dd 100644 (file)
@@ -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"