1
0
mirror of https://github.com/golang/go synced 2024-11-24 09:20:02 -07:00

go/types: adjust printing of type parameter in error

This is a clean port of CL 360514 to go/types.

Change-Id: Ia13638b3758b3b8017867934d09136ac5f9a62ca
Reviewed-on: https://go-review.googlesource.com/c/go/+/360935
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Robert Findley 2021-11-02 18:29:27 -04:00
parent 32d27527a6
commit d6f7203a3c
2 changed files with 5 additions and 4 deletions

View File

@ -373,7 +373,6 @@ func (check *Checker) inferB(tparams []*TypeParam, targs []Type) (types []Type,
// If a constraint has a structural type, unify the corresponding type parameter with it.
for _, tpar := range tparams {
typ := tpar
sbound := structure(tpar)
if sbound != nil {
// If the structural type is the underlying type of a single
@ -381,8 +380,10 @@ func (check *Checker) inferB(tparams []*TypeParam, targs []Type) (types []Type,
if named, _ := tpar.singleType().(*Named); named != nil {
sbound = named
}
if !u.unify(typ, sbound) {
check.errorf(tpar.obj, _Todo, "%s does not match %s", tpar.obj, sbound)
if !u.unify(tpar, sbound) {
// TODO(gri) improve error message by providing the type arguments
// which we know already
check.errorf(tpar.obj, _Todo, "%s does not match %s", tpar, sbound)
return nil, 0
}
}

View File

@ -5,7 +5,7 @@
package issue45985
// TODO(rFindley): this error should be on app[int] below.
func app[S /* ERROR "type S S does not match" */ interface{ ~[]T }, T any](s S, e T) S {
func app[S /* ERROR "S does not match" */ interface{ ~[]T }, T any](s S, e T) S {
return append(s, e)
}