aboutsummaryrefslogtreecommitdiff
path: root/src/go
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2021-04-20 23:10:09 -0400
committerRobert Findley <rfindley@google.com>2021-04-22 03:03:41 +0000
commitf0a8101d34b396c4dc9ea6581c03ce16419192ab (patch)
tree385d2f6c98796e92c9b7a1348f34cc899722fc90 /src/go
parent5daefc5363080acd631ae97a84faf651a70d9888 (diff)
downloadgo-f0a8101d34b396c4dc9ea6581c03ce16419192ab.tar.gz
go-f0a8101d34b396c4dc9ea6581c03ce16419192ab.zip
go/types: combine two loops (cleanup of TODO)
This is an exact port of CL 307949 to go/types. Change-Id: I796f3030a86d76deb80e58bb547460b586480911 Reviewed-on: https://go-review.googlesource.com/c/go/+/312096 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>
Diffstat (limited to 'src/go')
-rw-r--r--src/go/types/infer.go32
1 files changed, 11 insertions, 21 deletions
diff --git a/src/go/types/infer.go b/src/go/types/infer.go
index 9aae1bb248..8b491eb3ba 100644
--- a/src/go/types/infer.go
+++ b/src/go/types/infer.go
@@ -182,33 +182,23 @@ func (check *Checker) infer(posn positioner, tparams []*TypeName, targs []Type,
// Use any untyped arguments to infer additional type arguments.
// Some generic parameters with untyped arguments may have been given
// a type by now, we can ignore them.
- j := 0
for _, i := range indices {
par := params.At(i)
// Since untyped types are all basic (i.e., non-composite) types, an
// untyped argument will never match a composite parameter type; the
// only parameter type it can possibly match against is a *TypeParam.
- // Thus, only keep the indices of generic parameters that are not of
- // composite types and which don't have a type inferred yet.
+ // Thus, only consider untyped arguments for generic parameters that
+ // are not of composite types and which don't have a type inferred yet.
if tpar, _ := par.typ.(*_TypeParam); tpar != nil && targs[tpar.index] == nil {
- indices[j] = i
- j++
- }
- }
- indices = indices[:j]
-
- // Unify parameter and default argument types for remaining generic parameters.
- // TODO(gri) Rather than iterating again, combine this code with the loop above.
- for _, i := range indices {
- par := params.At(i)
- arg := args[i]
- targ := Default(arg.typ)
- // The default type for an untyped nil is untyped nil. We must not
- // infer an untyped nil type as type parameter type. Ignore untyped
- // nil by making sure all default argument types are typed.
- if isTyped(targ) && !u.unify(par.typ, targ) {
- errorf("default type", par.typ, targ, arg)
- return nil
+ arg := args[i]
+ targ := Default(arg.typ)
+ // The default type for an untyped nil is untyped nil. We must not
+ // infer an untyped nil type as type parameter type. Ignore untyped
+ // nil by making sure all default argument types are typed.
+ if isTyped(targ) && !u.unify(par.typ, targ) {
+ errorf("default type", par.typ, targ, arg)
+ return nil
+ }
}
}