apache/beam · error
Incompatible func type: got func
Error message
Incompatible func type: got func %v with %v inputs and %v outputs, want 1 inputs and 3 outputs
What it means
ToFunc1x3 adapts a generic reflectx Func into a Func1x3 (1 input, 3 outputs). It panics when the wrapped function's reflect type does not have exactly 1 input and 3 outputs, failing fast at adaptation time.
Solutions
- Change the function to return exactly 3 values with 1 input.
- Use the ToFunc/MakeFuncNxM variant matching the actual arity.
- Check NumIn()/NumOut() on the Func type first.
Example fix
// before
reflectx.MakeFunc1x3(func(x int) (int, int) { return x, x }) // panics: 2 outputs
// after
reflectx.MakeFunc1x3(func(x int) (int, int, int) { return x, x, x }) Defensive patterns
Strategy: validation
Validate before calling
t := c.Type()
if t.NumIn() != 1 || t.NumOut() != 3 {
return fmt.Errorf("func %v has %d ins/%d outs; ToFunc1x3 needs 1 in/3 outs", t, t.NumIn(), t.NumOut())
} Type guard
func isFunc1x3(c reflectx.Func) bool {
return c.Type().NumIn() == 1 && c.Type().NumOut() == 3
} Try / catch
func safeToFunc1x3(c reflectx.Func) (f reflectx.Func1x3) {
defer func() {
if r := recover(); r != nil {
log.Fatalf("ToFunc1x3 arity mismatch: %v", r)
}
}()
return reflectx.ToFunc1x3(c)
} Prevention
- Count return values explicitly when writing multi-output functions.
- Keep helper variant selection (MakeFunc1x3) reviewed together with the function literal.
- Write a smoke test that constructs every wrapper at startup.
When it happens
Trigger: Calling reflectx.ToFunc1x3 or MakeFunc1x3 with a Func whose Type().NumIn() != 1 or Type().NumOut() != 3.
Common situations: A multi-output function updated to return a different number of values without updating the adapter call; copying a 1x2 adapter and forgetting to update the expected output count.
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/ea657bad393f445d.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/util/reflectx/calls.go:393
}
func (c *shimFunc1x3) Type() reflect.Type {
return c.inner.Type()
}
func (c *shimFunc1x3) Call(args []any) []any {
return c.inner.Call(args)
}
func (c *shimFunc1x3) Call1x3(arg0 any) (any, any, any) {
ret := c.inner.Call([]any{arg0})
_ = ret
return ret[0], ret[1], ret[2]
}
func ToFunc1x3(c Func) Func1x3 {
if c.Type().NumIn() != 1 || c.Type().NumOut() != 3 {
panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 1 inputs and 3 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
}
if sc, ok := c.(Func1x3); ok {
return sc
}
return &shimFunc1x3{inner: c}
}
func MakeFunc1x3(fn any) Func1x3 {
return ToFunc1x3(MakeFunc(fn))
}
type Func1x4 interface {
Func
Call1x4(any) (any, any, any, any)
}
type shimFunc1x4 struct {
inner FuncView on GitHub (pinned to 12126d8942)