aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-04-06 22:46:57 -0700
committerRobert Griesemer <gri@golang.org>2021-04-07 16:57:40 +0000
commitb3064b66d0699618cae07e97068f653410b71abc (patch)
tree87100f9c381b43cafab0a846f1b69f9d6722d02c /src
parent4520da486b6d236090b1d98ce4707c5bcd19cb70 (diff)
downloadgo-b3064b66d0699618cae07e97068f653410b71abc.tar.xz
cmd/compile/internal/types2: combine two loops (cleanup of TODO)
Follow-up on https://golang.org/cl/306170. Change-Id: I71b451382b6780101a0c94174ebe579e8a0684c2 Reviewed-on: https://go-review.googlesource.com/c/go/+/307949 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/types2/infer.go32
1 files changed, 11 insertions, 21 deletions
diff --git a/src/cmd/compile/internal/types2/infer.go b/src/cmd/compile/internal/types2/infer.go
index 995ebd7ea0..13a9ccda0c 100644
--- a/src/cmd/compile/internal/types2/infer.go
+++ b/src/cmd/compile/internal/types2/infer.go
@@ -184,33 +184,23 @@ func (check *Checker) infer(pos syntax.Pos, tparams []*TypeName, targs []Type, p
// 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
+ }
}
}