1
0
mirror of https://github.com/golang/go synced 2024-09-30 01:14:29 -06:00

go/types, types2: simplify unification with constraints

Change-Id: I399f0ac12e65713f3018a89da55ecd3cdb855c50
Reviewed-on: https://go-review.googlesource.com/c/go/+/471017
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2023-02-23 18:55:11 -08:00 committed by Gopher Robot
parent 997dbcf6ba
commit e2f2123e25
2 changed files with 20 additions and 20 deletions

View File

@ -198,16 +198,16 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeParam, targs []Type,
tx := u.at(tpar)
switch {
case tx != nil:
// The corresponding type argument tx is known.
// In this case, if the core type has a tilde, the type argument's underlying
// type must match the core type, otherwise the type argument and the core type
// must match.
// If tx is an (external) type parameter, don't consider its underlying type
// (which is an interface). The unifier will use the type parameter's core
// type automatically.
if core.tilde && !isTypeParam(tx) {
tx = under(tx)
}
// The corresponding type argument tx is known. There are 2 cases:
// 1) If the core type has a tilde, per spec requirement for tilde
// elements, the core type is an underlying (literal) type.
// And because of the tilde, the underlying type of tx must match
// against the core type.
// But because unify automatically matches a defined type against
// an underlying literal type, we can simply unify tx with the
// core type.
// 2) If the core type doesn't have a tilde, we also must unify tx
// with the core type.
if !u.unify(tx, core.typ) {
check.errorf(pos, CannotInferTypeArgs, "%s does not match %s", tpar, core.typ)
return nil

View File

@ -200,16 +200,16 @@ func (check *Checker) infer(posn positioner, tparams []*TypeParam, targs []Type,
tx := u.at(tpar)
switch {
case tx != nil:
// The corresponding type argument tx is known.
// In this case, if the core type has a tilde, the type argument's underlying
// type must match the core type, otherwise the type argument and the core type
// must match.
// If tx is an (external) type parameter, don't consider its underlying type
// (which is an interface). The unifier will use the type parameter's core
// type automatically.
if core.tilde && !isTypeParam(tx) {
tx = under(tx)
}
// The corresponding type argument tx is known. There are 2 cases:
// 1) If the core type has a tilde, per spec requirement for tilde
// elements, the core type is an underlying (literal) type.
// And because of the tilde, the underlying type of tx must match
// against the core type.
// But because unify automatically matches a defined type against
// an underlying literal type, we can simply unify tx with the
// core type.
// 2) If the core type doesn't have a tilde, we also must unify tx
// with the core type.
if !u.unify(tx, core.typ) {
check.errorf(posn, CannotInferTypeArgs, "%s does not match %s", tpar, core.typ)
return nil