// on the corresponding in/out parameters in dcl. It depends on the in and out
// parameters being in order in dcl.
func (subst *subster) fields(class ir.Class, oldfields []*types.Field, dcl []*ir.Name) []*types.Field {
- newfields := make([]*types.Field, len(oldfields))
- var i int
-
// Find the starting index in dcl of declarations of the class (either
// PPARAM or PPARAMOUT).
+ var i int
for i = range dcl {
if dcl[i].Class == class {
break
// Create newfields nodes that are copies of the oldfields nodes, but
// with substitution for any type params, and with Nname set to be the node in
// Dcl for the corresponding PPARAM or PPARAMOUT.
+ newfields := make([]*types.Field, len(oldfields))
for j := range oldfields {
newfields[j] = oldfields[j].Copy()
newfields[j].Type = subst.typ(oldfields[j].Type)
- newfields[j].Nname = dcl[i]
- i++
+ // A param field will be missing from dcl if its name is
+ // unspecified or specified as "_". So, we compare the dcl sym
+ // with the field sym. If they don't match, this dcl (if there is
+ // one left) must apply to a later field.
+ if i < len(dcl) && dcl[i].Sym() == oldfields[j].Sym {
+ newfields[j].Nname = dcl[i]
+ i++
+ }
}
return newfields
}
// Testing partial and full type inference, including the case where the types can
// be inferred without needing the types of the function arguments.
-func f0[A any, B interface{type C}, C interface{type D}, D interface{type A}](a A, b B, c C, d D)
+func f0[A any, B interface{type C}, C interface{type D}, D interface{type A}](A, B, C, D)
func _() {
f := f0[string]
f("a", "b", "c", "d")
f0("a", "b", "c", "d")
}
-func f1[A any, B interface{type A}](a A, b B)
+func f1[A any, B interface{type A}](A, B)
func _() {
f := f1[int]
f(int(0), int(0))
f1(0, 0)
}
-func f2[A any, B interface{type []A}](a A, b B)
+func f2[A any, B interface{type []A}](_ A, _ B)
func _() {
f := f2[byte]
f(byte(0), []byte{})
// f2(0, []byte{}) - this one doesn't work
}
-func f3[A any, B interface{type C}, C interface{type *A}](a A, b B, c C)
+func f3[A any, B interface{type C}, C interface{type *A}](a A, _ B, c C)
func _() {
f := f3[int]
var x int
f3(x, &x, &x)
}
-func f4[A any, B interface{type []C}, C interface{type *A}](a A, b B, c C)
+func f4[A any, B interface{type []C}, C interface{type *A}](_ A, _ B, c C)
func _() {
f := f4[int]
var x int