apache/beam · error

Incompatible func type: got func %v with %v inputs and %v ou

Error message

Incompatible func type: got func %v with %v inputs and %v outputs, want 7 inputs and 3 outputs

What it means

reflectx.ToFunc7x3 adapts a Func to a strongly-typed 7-input/3-output function. It panics when the wrapped function's reflect.Type reports NumIn != 7 or NumOut != 3, because the shim returns exactly ret[0], ret[1], ret[2]. The panic names both got and want arity.

Source

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

}

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

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

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

func ToFunc7x3(c Func) Func7x3 {
	if c.Type().NumIn() != 7 || c.Type().NumOut() != 3 {
		panic(fmt.Sprintf("Incompatible func type: got func %v with %v inputs and %v outputs, want 7 inputs and 3 outputs", c.Type(), c.Type().NumIn(), c.Type().NumOut()))
	}
	if sc, ok := c.(Func7x3); ok {
		return sc
	}
	return &shimFunc7x3{inner: c}
}

func MakeFunc7x3(fn any) Func7x3 {
	return ToFunc7x3(MakeFunc(fn))
}

type Func7x4 interface {
	Func
	Call7x4(any, any, any, any, any, any, any) (any, any, any, any)
}

type shimFunc7x4 struct {
	inner Func

View on GitHub (pinned to 12126d8942)

Solutions

  1. Change the function to exactly 7 inputs and 3 outputs
  2. Switch to the converter matching the actual arity (ToFunc7x2, ToFunc8x3, etc.)
  3. Fix the intended registration target if the FuncNxM type was chosen wrong
  4. Add a unit test asserting the converted type before building the pipeline

Example fix

// before
func(a, b, c, d, e, f2, g any) (any, any) { ... } // 2 outputs
reflectx.ToFunc7x3(reflectx.NewFunc(fn)) // panics
// after
func(a, b, c, d, e, f2, g any) (any, any, any) { ... } // 3 outputs
reflectx.ToFunc7x3(reflectx.NewFunc(fn)) // OK
Defensive patterns

Strategy: validation

Validate before calling

t := f.Type()
if t.NumIn() != 7 || t.NumOut() != 3 {
    return fmt.Errorf("ToFunc7x3 needs 7 in / 3 out, got %d in / %d out (%v)", t.NumIn(), t.NumOut(), t)
}

Type guard

func isFunc7x3(f reflectx.Func) bool {
    t := f.Type()
    return t.NumIn() == 7 && t.NumOut() == 3
}

Try / catch

func safeToFunc7x3(f reflectx.Func) (fn reflectx.Func7x3, err error) {
    defer func() {
        if r := recover(); r != nil {
            err = fmt.Errorf("conversion failed: %v", r)
        }
    }()
    fn = reflectx.ToFunc7x3(f)
    return
}

Prevention

When it happens

Trigger: Calling ToFunc7x3 (or MakeFunc7x3) with a Func of any other shape, e.g. a 7-in/2-out function or an 8-in/3-out function.

Common situations: Multi-output DoFns where an output (or an error return) was added/removed; moving a function between pipeline stages with different arity slots; off-by-one in generated Beam code selecting converters.

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/41eef04a99a71a41. Report an issue: GitHub.