{"record":{"id":"685f5d542bf17b23","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-685f5d","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 3 inputs and 4 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 3 inputs and 4 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":844,"sourceCode":"}\n\nfunc (c *shimFunc3x4) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc3x4) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc3x4) Call3x4(arg0, arg1, arg2 any) (any, any, any, any) {\n\tret := c.inner.Call([]any{arg0, arg1, arg2})\n\t_ = ret\n\treturn ret[0], ret[1], ret[2], ret[3]\n}\n\nfunc ToFunc3x4(c Func) Func3x4 {\n\tif c.Type().NumIn() != 3 || c.Type().NumOut() != 4 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 3 inputs and 4 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func3x4); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc3x4{inner: c}\n}\n\nfunc MakeFunc3x4(fn any) Func3x4 {\n\treturn ToFunc3x4(MakeFunc(fn))\n}\n\ntype Func4x0 interface {\n\tFunc\n\tCall4x0(any, any, any, any)\n}\n\ntype shimFunc4x0 struct {\n\tinner Func","sourceCodeStart":826,"sourceCodeEnd":862,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L826-L862","documentation":"reflectx.ToFunc3x4 converts a generic Func to a strongly-typed Func3x4 (3 inputs, 4 outputs). The converter checks that the underlying reflect.Type has exactly NumIn()==3 and NumOut()==4 and panics otherwise. The Beam Go SDK fails fast here because its fixed-arity shim would otherwise mis-dispatch return values during pipeline execution.","triggerScenarios":"Calling reflectx.ToFunc3x4(f) where f.Type().NumIn() != 3 (e.g. 2 or 4 params) or f.Type().NumOut() != 4 (e.g. 2 or 3 return values, such as a function returning (T, error)).","commonSituations":"Functions returning (value1, value2, error) — 3 outputs, not 4 — passed to the wrong converter; an emitter parameter added to the function after the converter call was written; copy-pasted converter names not updated when a function signature changed.","solutions":["Adjust the function to accept exactly 3 parameters and return exactly 4 values.","Pick the converter matching the actual shape (ToFunc3x3 for 3 outputs, ToFunc3x2 for 2).","Validate with reflect.TypeOf(fn).NumIn()/NumOut() before calling ToFunc3x4.","If 4 outputs are needed but the function lacks one, add the extra return (e.g. an emitter or boolean) at the function definition site."],"exampleFix":"// before\nf := reflectx.ToFunc3x4(func(a int, b, c string) (int, string, error) { return a, b, nil }) // 3 outputs, panics\n// after\nf := reflectx.ToFunc3x3(func(a int, b, c string) (int, string, error) { return a, b, nil })","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(fn)\nif t.NumIn() != 3 || t.NumOut() != 4 {\n    panic(fmt.Sprintf(\"expected 3-in/4-out func, got %v (%d in, %d out)\", t, t.NumIn(), t.NumOut()))\n}\nf := reflectx.ToFunc3x4(f)","typeGuard":"func isFunc3x4(fn any) bool {\n    t := reflect.TypeOf(fn)\n    return t != nil && t.Kind() == reflect.Func && t.NumIn() == 3 && t.NumOut() == 4\n}","tryCatchPattern":"func safeToFunc3x4(f reflectx.Func) (out reflectx.Func3x4, err error) {\n    defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"ToFunc3x4: %v\", r) } }()\n    out = reflectx.ToFunc3x4(f)\n    return\n}","preventionTips":["Fix the converter name in the same change that adds/removes a return value.","Document in team conventions that the NxM suffix must equal the literal param/return counts.","Add a CI check or test asserting reflect arity for all reflectx-wrapped functions.","Remember that a trailing error return inflates the output count."],"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-14T16:17:12.679Z"}