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 0 outputs
What it means
ToFunc2x0 adapts a generic reflectx Func into a Func2x0 (2 inputs, 0 outputs, a binary consumer). It panics when the wrapped function's type does not have exactly 2 inputs and 0 outputs, so arity mismatches fail at construction rather than at call time.
Solutions
- Make the wrapped function take exactly 2 inputs and return nothing.
- Use the ToFunc/MakeFuncNxM variant matching the actual signature.
- Verify c.Type().NumIn()==2 && c.Type().NumOut()==0 before wrapping.
Example fix
// before
reflectx.MakeFunc2x0(func(a, b int) int { return a + b }) // panics: 1 output
// after
reflectx.MakeFunc2x0(func(a, b int) { _ = a + b }) Defensive patterns
Strategy: validation
Validate before calling
t := c.Type()
if t.NumIn() != 2 || t.NumOut() != 0 {
return fmt.Errorf("func %v has %d ins/%d outs; ToFunc2x0 needs 2 ins/0 outs", t, t.NumIn(), t.NumOut())
} Type guard
func isFunc2x0(c reflectx.Func) bool {
return c.Type().NumIn() == 2 && c.Type().NumOut() == 0
} Try / catch
func safeToFunc2x0(c reflectx.Func) (f reflectx.Func2x0) {
defer func() {
if r := recover(); r != nil {
log.Fatalf("ToFunc2x0 arity mismatch: %v", r)
}
}()
return reflectx.ToFunc2x0(c)
} Prevention
- Sinks must return nothing; strip error returns or switch to a variant with outputs.
- Check parameter count when converting a 1-input consumer to a 2-input one.
- Assert arity in tests for all sink wrappers.
When it happens
Trigger: Calling reflectx.ToFunc2x0 (or its MakeFunc2x0 helper) with a Func whose Type().NumIn() != 2 or Type().NumOut() != 0, e.g. a one-argument sink or one that returns a value.
Common situations: Writing a combine/sink function that lost or gained a parameter; wrapping a function that still returns an error; using the wrong helper variant after a signature change.
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/03868318aab0ce8d.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/util/reflectx/calls.go:475
}
func (c *shimFunc2x0) Type() reflect.Type {
return c.inner.Type()
}
func (c *shimFunc2x0) Call(args []any) []any {
return c.inner.Call(args)
}
func (c *shimFunc2x0) Call2x0(arg0, arg1 any) {
ret := c.inner.Call([]any{arg0, arg1})
_ = ret
return
}
func ToFunc2x0(c Func) Func2x0 {
if c.Type().NumIn() != 2 || c.Type().NumOut() != 0 {
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 0 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
}
if sc, ok := c.(Func2x0); ok {
return sc
}
return &shimFunc2x0{inner: c}
}
func MakeFunc2x0(fn any) Func2x0 {
return ToFunc2x0(MakeFunc(fn))
}
type Func2x1 interface {
Func
Call2x1(any, any) any
}
type shimFunc2x1 struct {
inner FuncView on GitHub (pinned to 12126d8942)