apache/beam · error

Incompatible func type: got func

Error message

Incompatible func type: got func %v with %v inputs and %v outputs, want 8 inputs and 4 outputs

What it means

reflectx.ToFunc8x4 converts a generic Func wrapper into a Func8x4 typed signature. The library panics because a function with 8 inputs and 4 outputs is required to build the typed shim; any other arity cannot be represented by Func8x4.

Solutions

  1. Count the function's actual inputs and outputs and call the matching ToFunc variant (e.g. ToFunc8x3, ToFunc9x4).
  2. Adjust the wrapped function's signature to exactly 8 parameters and 4 return values.
  3. If the arity is dynamic, keep the generic Func instead of converting to a typed Func8x4.

Example fix

// before
f := reflectx.NewFunc(func(a int) int { return a })
f8x4 := reflectx.ToFunc8x4(f) // panics
// after
f := reflectx.NewFunc(func(a,b,c,d,e,f2,g,h int) (int,int,int,int) { return a,b,c,d })
f8x4 := reflectx.ToFunc8x4(f)
Defensive patterns

Strategy: validation

Validate before calling

t := c.Type()
if t.NumIn() != 8 || t.NumOut() != 4 {
    panic(fmt.Sprintf("cannot convert to Func8x4: %d inputs, %d outputs", t.NumIn(), t.NumOut()))
}

Type guard

func isFunc8x4(v any) bool {
    t := reflect.TypeOf(v)
    return t != nil && t.Kind() == reflect.Func && t.NumIn() == 8 && t.NumOut() == 4
}

Try / catch

func safeToFunc8x4(c reflectx.Func) (f reflectx.Func8x4, err error) {
    defer func() {
        if r := recover(); r != nil {
            err = fmt.Errorf("ToFunc8x4 failed: %v", r)
        }
    }()
    return reflectx.ToFunc8x4(c), nil
}

Prevention

When it happens

Trigger: Calling ToFunc8x4(c) where c.Type().NumIn() != 8 or c.Type().NumOut() != 4.

Common situations: Passing a function built with reflectx.NewFunc or reflect.MakeFunc whose signature was changed (inputs or outputs added/removed) without updating the ToFuncNxM variant used.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/987b23d3cd108e1f. Report an issue: GitHub.

Appendix: source

Thrown at sdks/go/pkg/beam/core/util/reflectx/calls.go:1869

}

func (c *shimFunc8x4) Type() reflect.Type {
	return c.inner.Type()
}

func (c *shimFunc8x4) Call(args []any) []any {
	return c.inner.Call(args)
}

func (c *shimFunc8x4) Call8x4(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 any) (any, any, any, any) {
	ret := c.inner.Call([]any{arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7})
	_ = ret
	return ret[0], ret[1], ret[2], ret[3]
}

func ToFunc8x4(c Func) Func8x4 {
	if c.Type().NumIn() != 8 || c.Type().NumOut() != 4 {
		panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 8 inputs and 4 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
	}
	if sc, ok := c.(Func8x4); ok {
		return sc
	}
	return &shimFunc8x4{inner: c}
}

func MakeFunc8x4(fn any) Func8x4 {
	return ToFunc8x4(MakeFunc(fn))
}

View on GitHub (pinned to 12126d8942)