An untyped nil argument cannot be used to infer any type information.
We don't need to include it in the untyped arguments.
Change-Id: Ied44738ff1b135e65a3acfa19223cd3889b7fa7d
Reviewed-on: https://go-review.googlesource.com/c/go/+/492695
Reviewed-by: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
errorf("type", par.typ, arg.typ, arg)
return nil
}
- } else if _, ok := par.typ.(*TypeParam); ok {
+ } else if _, ok := par.typ.(*TypeParam); ok && !arg.isNil() {
// Since default 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, for untyped arguments we only need to look at parameter types
// that are single type parameters.
+ // Also, untyped nils don't have a default type and can be ignored.
untyped = append(untyped, i)
}
}
j++
}
}
- // untyped[:j] are the indices of parameters without a type yet
+ // untyped[:j] are the indices of parameters without a type yet.
+ // The respective default types are typed (not untyped) by construction.
for _, i := range untyped[:j] {
tpar := params.At(i).typ.(*TypeParam)
arg := args[i]
typ := Default(arg.typ)
- // The default type for an untyped nil is untyped nil which must
- // not be inferred as type parameter type. Ignore them by making
- // sure all default types are typed.
- if isTyped(typ) && !u.unify(tpar, typ) {
+ assert(isTyped(typ))
+ if !u.unify(tpar, typ) {
errorf("default type", tpar, typ, arg)
return nil
}
x.val = val
}
-// isNil reports whether x is a typed or the untyped nil value.
+// isNil reports whether x is the (untyped) nil value.
func (x *operand) isNil() bool { return x.mode == nilvalue }
// assignableTo reports whether x is assignable to a variable of type T. If the
errorf("type", par.typ, arg.typ, arg)
return nil
}
- } else if _, ok := par.typ.(*TypeParam); ok {
+ } else if _, ok := par.typ.(*TypeParam); ok && !arg.isNil() {
// Since default 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, for untyped arguments we only need to look at parameter types
// that are single type parameters.
+ // Also, untyped nils don't have a default type and can be ignored.
untyped = append(untyped, i)
}
}
j++
}
}
- // untyped[:j] are the indices of parameters without a type yet
+ // untyped[:j] are the indices of parameters without a type yet.
+ // The respective default types are typed (not untyped) by construction.
for _, i := range untyped[:j] {
tpar := params.At(i).typ.(*TypeParam)
arg := args[i]
typ := Default(arg.typ)
- // The default type for an untyped nil is untyped nil which must
- // not be inferred as type parameter type. Ignore them by making
- // sure all default types are typed.
- if isTyped(typ) && !u.unify(tpar, typ) {
+ assert(isTyped(typ))
+ if !u.unify(tpar, typ) {
errorf("default type", tpar, typ, arg)
return nil
}
x.val = val
}
-// isNil reports whether x is the nil value.
-func (x *operand) isNil() bool {
- return x.mode == value && x.typ == Typ[UntypedNil]
-}
+// isNil reports whether x is the (untyped) nil value.
+func (x *operand) isNil() bool { return x.mode == value && x.typ == Typ[UntypedNil] }
// assignableTo reports whether x is assignable to a variable of type T. If the
// result is false and a non-nil cause is provided, it may be set to a more