apache/beam · error
Incompatible func type: got func
Error message
Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 1 outputs
What it means
ToFunc2x1 adapts a generic reflectx Func into a Func2x1 (2 inputs, 1 output, a binary merge function). It panics unless the wrapped function has exactly 2 inputs and 1 output, catching signature mismatches at adaptation time.
Solutions
- Make the function take exactly 2 inputs and return exactly 1 value.
- Pick the matching arity variant.
- Check NumIn()/NumOut() on the Func's type first.
Example fix
// before
reflectx.MakeFunc2x1(func(a, b int) (int, error) { return a + b, nil }) // panics
// after
reflectx.MakeFunc2x1(func(a, b int) int { return a + b }) Defensive patterns
Strategy: validation
Validate before calling
t := c.Type()
if t.NumIn() != 2 || t.NumOut() != 1 {
return fmt.Errorf("func %v has %d ins/%d outs; ToFunc2x1 needs 2 ins/1 out", t, t.NumIn(), t.NumOut())
} Type guard
func isFunc2x1(c reflectx.Func) bool {
return c.Type().NumIn() == 2 && c.Type().NumOut() == 1
} Try / catch
func safeToFunc2x1(c reflectx.Func) (f reflectx.Func2x1) {
defer func() {
if r := recover(); r != nil {
log.Fatalf("ToFunc2x1 arity mismatch: %v", r)
}
}()
return reflectx.ToFunc2x1(c)
} Prevention
- Merge/combine functions should not return errors in this API; handle errors outside the wrapper.
- Verify both inputs exist when adapting from 1x1 to 2x1.
- Keep a test that builds all combiners at init.
When it happens
Trigger: Calling reflectx.ToFunc2x1 with a Func whose Type().NumIn() != 2 or Type().NumOut() != 1, e.g. a combiner that also returns an error or takes a context.
Common situations: Merge/combine functions refactored to return (V, error); passing a 1-input function to a 2-input helper; wrong MakeFuncNxM variant chosen.
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
- Incompatible func type: got func
- Incompatible func type: got func
- Incompatible func type: got func
- Incompatible func type: got func
- Incompatible func type: got func
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/9358d96d752eeffc.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/util/reflectx/calls.go:516
}
func (c *shimFunc2x1) Type() reflect.Type {
return c.inner.Type()
}
func (c *shimFunc2x1) Call(args []any) []any {
return c.inner.Call(args)
}
func (c *shimFunc2x1) Call2x1(arg0, arg1 any) any {
ret := c.inner.Call([]any{arg0, arg1})
_ = ret
return ret[0]
}
func ToFunc2x1(c Func) Func2x1 {
if c.Type().NumIn() != 2 || c.Type().NumOut() != 1 {
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 1 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
}
if sc, ok := c.(Func2x1); ok {
return sc
}
return &shimFunc2x1{inner: c}
}
func MakeFunc2x1(fn any) Func2x1 {
return ToFunc2x1(MakeFunc(fn))
}
type Func2x2 interface {
Func
Call2x2(any, any) (any, any)
}
type shimFunc2x2 struct {
inner FuncView on GitHub (pinned to 12126d8942)