{"record":{"id":"0bc0b7848a2e616a","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-0bc0b7","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 4 inputs and 2 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 4 inputs and 2 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":967,"sourceCode":"}\n\nfunc (c *shimFunc4x2) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc4x2) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc4x2) Call4x2(arg0, arg1, arg2, arg3 any) (any, any) {\n\tret := c.inner.Call([]any{arg0, arg1, arg2, arg3})\n\t_ = ret\n\treturn ret[0], ret[1]\n}\n\nfunc ToFunc4x2(c Func) Func4x2 {\n\tif c.Type().NumIn() != 4 || c.Type().NumOut() != 2 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 4 inputs and 2 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func4x2); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc4x2{inner: c}\n}\n\nfunc MakeFunc4x2(fn any) Func4x2 {\n\treturn ToFunc4x2(MakeFunc(fn))\n}\n\ntype Func4x3 interface {\n\tFunc\n\tCall4x3(any, any, any, any) (any, any, any)\n}\n\ntype shimFunc4x3 struct {\n\tinner Func","sourceCodeStart":949,"sourceCodeEnd":985,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L949-L985","documentation":"reflectx.ToFunc4x2 converts a generic Func to a strongly-typed Func4x2 (4 inputs, 2 outputs). It panics when the underlying reflect.Type does not have exactly NumIn()==4 and NumOut()==2. Beam throws this at conversion time so the fixed-arity shim's two-value return handling matches the wrapped function, printing the actual func type and counts in the panic message.","triggerScenarios":"Calling reflectx.ToFunc4x2(f) where f.Type().NumIn() != 4 (e.g. 3 or 5 params) or f.Type().NumOut() != 2 (1 return, or 3+ returns).","commonSituations":"A function that dropped its error/bool return (now 1 output) or gained a third output; a helper parameter removed from the function signature after the converter call was written; wrong converter chosen for a simple single-return mapper.","solutions":["Make the function take exactly 4 parameters and return exactly 2 values.","Use ToFunc4x1 for single-output or ToFunc4x3 for three-output functions.","Check reflect.TypeOf(fn).NumIn()/NumOut() before coercing.","Prefer beam's typed DoFn/Func registration when arity keeps drifting, so Beam derives the shim instead of manual converters."],"exampleFix":"// before\nf := reflectx.ToFunc4x2(func(a int, b string, c bool, d float64) int { return a }) // 1 output, panics\n// after\nf := reflectx.ToFunc4x2(func(a int, b string, c bool, d float64) (int, bool) { return a, c })","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(fn)\nif t.NumIn() != 4 || t.NumOut() != 2 {\n    panic(fmt.Sprintf(\"expected 4-in/2-out func, got %v (%d in, %d out)\", t, t.NumIn(), t.NumOut()))\n}\nf := reflectx.ToFunc4x2(f)","typeGuard":"func isFunc4x2(fn any) bool {\n    t := reflect.TypeOf(fn)\n    return t != nil && t.Kind() == reflect.Func && t.NumIn() == 4 && t.NumOut() == 2\n}","tryCatchPattern":"func safeToFunc4x2(f reflectx.Func) (out reflectx.Func4x2, err error) {\n    defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"ToFunc4x2: %v\", r) } }()\n    out = reflectx.ToFunc4x2(f)\n    return\n}","preventionTips":["Count every return value including errors when picking NxM.","Test-assert NumIn/NumOut for all wrapped functions.","Avoid propagating converter names via copy-paste; derive them from the literal signature.","Consider typed DoFn registration if arities change frequently."],"tags":["go","apache-beam","reflection","panic","function-signature"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}