apache/beam · error

Incompatible func type: got func

Error message

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

What it means

reflectx.ToFunc0x3 adapts a Func to Func0x3 (0 inputs, 3 outputs) and panics unless the reflect type has exactly 0 inputs and 3 outputs. The panic message reports the actual function type with its input and output counts.

Solutions

  1. Use ToFunc0x2 if the function now returns only two values.
  2. Ensure the function is a plain closure with zero parameters and exactly three returns.
  3. Verify with fn.Type().NumIn() and fn.Type().NumOut() before choosing the adapter, and pick the matching ToFuncNxx.

Example fix

// before
reflectx.ToFunc0x3(reflectx.MakeFunc(func() (int, int) { ... }))
// after
reflectx.ToFunc0x2(reflectx.MakeFunc(func() (int, int) { ... }))
Defensive patterns

Strategy: validation

Validate before calling

func isFunc0x3(fn reflectx.Func) bool {
    return fn.Type().NumIn() == 0 && fn.Type().NumOut() == 3
}

Type guard

func asFunc0x3(fn reflectx.Func) (reflectx.Func0x3, bool) {
    if f, ok := fn.(reflectx.Func0x3); ok { return f, true }
    return nil, false
}

Try / catch

func safeToFunc0x3(fn reflectx.Func) (f reflectx.Func0x3, err error) {
    defer func() {
        if r := recover(); r != nil { err = fmt.Errorf("ToFunc0x3: %v", r) }
    }()
    return reflectx.ToFunc0x3(fn), nil
}

Prevention

When it happens

Trigger: Calling ToFunc0x3 or MakeFunc0x3 with a func whose signature is not func() (A, B, C) — e.g. func() (A, B) (two returns) or func(ctx, x) (A, B, C) (inputs present).

Common situations: Switching a generator from three returns to two (e.g. dropping the error) without changing the adapter; wrapping a function with receiver-bound parameters that appear as extra inputs in the reflect type.

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/0bd9ba869c088c29. Report an issue: GitHub.

Appendix: source

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

}

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

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

func (c *shimFunc0x3) Call0x3() (any, any, any) {
	ret := c.inner.Call([]any{})
	_ = ret
	return ret[0], ret[1], ret[2]
}

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

func MakeFunc0x3(fn any) Func0x3 {
	return ToFunc0x3(MakeFunc(fn))
}

type Func0x4 interface {
	Func
	Call0x4() (any, any, any, any)
}

type shimFunc0x4 struct {
	inner Func

View on GitHub (pinned to 12126d8942)