diff options
author | Robert Griesemer <gri@golang.org> | 2022-01-27 12:53:13 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2022-01-28 22:21:51 +0000 |
commit | 8f7d96f5bcb927a576a43b890f2643e521107665 (patch) | |
tree | 1677078ee2965b398b12a2e152f19b0a18f50b62 | |
parent | 25b4b862f29900af00c794424b033b01eb5ab0cb (diff) | |
download | go-8f7d96f5bcb927a576a43b890f2643e521107665.tar.gz go-8f7d96f5bcb927a576a43b890f2643e521107665.zip |
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>
-rw-r--r-- | src/cmd/compile/internal/types2/api.go | 2 | ||||
-rw-r--r-- | src/cmd/compile/internal/types2/instantiate.go | 17 | ||||
-rw-r--r-- | src/cmd/compile/internal/types2/operand.go | 8 | ||||
-rw-r--r-- | src/go/types/api.go | 2 | ||||
-rw-r--r-- | src/go/types/instantiate.go | 17 | ||||
-rw-r--r-- | src/go/types/operand.go | 8 |
6 files changed, 18 insertions, 36 deletions
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" |