{"record":{"id":"e5e0083596655229","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-e5e008","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 7 inputs and 4 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 7 inputs and 4 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":1664,"sourceCode":"}\n\nfunc (c *shimFunc7x4) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc7x4) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc7x4) Call7x4(arg0, arg1, arg2, arg3, arg4, arg5, arg6 any) (any, any, any, any) {\n\tret := c.inner.Call([]any{arg0, arg1, arg2, arg3, arg4, arg5, arg6})\n\t_ = ret\n\treturn ret[0], ret[1], ret[2], ret[3]\n}\n\nfunc ToFunc7x4(c Func) Func7x4 {\n\tif c.Type().NumIn() != 7 || c.Type().NumOut() != 4 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 7 inputs and 4 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func7x4); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc7x4{inner: c}\n}\n\nfunc MakeFunc7x4(fn any) Func7x4 {\n\treturn ToFunc7x4(MakeFunc(fn))\n}\n\ntype Func8x0 interface {\n\tFunc\n\tCall8x0(any, any, any, any, any, any, any, any)\n}\n\ntype shimFunc8x0 struct {\n\tinner Func","sourceCodeStart":1646,"sourceCodeEnd":1682,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L1646-L1682","documentation":"reflectx.ToFunc7x4 converts a Func into a 7-input/4-output typed function and panics on any arity mismatch. The shim returns ret[0]..ret[3], so exactly 4 outputs and 7 inputs are mandatory. This surfaces at graph-construction time as a panic with the offending func type in the message.","triggerScenarios":"Calling ToFunc7x4 (or MakeFunc7x4) with a Func whose signature has inputs != 7 or outputs != 4, e.g. a 7-in/3-out or 8-in/4-out function.","commonSituations":"Beam DoFns emitting multiple collections where one output was added (3->4) without updating the wrapper; arity drift after API refactors; mistakenly passing the raw Go func without the matching NewFunc/Func type.","solutions":["Adjust the function to exactly 7 parameters and 4 return values","Use the matching ToFuncNxM for the real signature (e.g. ToFunc7x3, ToFunc8x4)","Align the converter choice with the pipeline stage's expected outputs","Check NumIn/NumOut before converting in generic/plugin code"],"exampleFix":"// before\nfunc(a, b, c, d, e, f2, g any) (any, any, any) { ... } // 3 outputs\nreflectx.ToFunc7x4(reflectx.NewFunc(fn)) // panics\n// after\nfunc(a, b, c, d, e, f2, g any) (any, any, any, any) { ... } // 4 outputs\nreflectx.ToFunc7x4(reflectx.NewFunc(fn)) // OK","handlingStrategy":"validation","validationCode":"t := f.Type()\nif t.NumIn() != 7 || t.NumOut() != 4 {\n    return fmt.Errorf(\"ToFunc7x4 needs 7 in / 4 out, got %d in / %d out (%v)\", t.NumIn(), t.NumOut(), t)\n}","typeGuard":"func isFunc7x4(f reflectx.Func) bool {\n    t := f.Type()\n    return t.NumIn() == 7 && t.NumOut() == 4\n}","tryCatchPattern":"func safeToFunc7x4(f reflectx.Func) (fn reflectx.Func7x4, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"conversion failed: %v\", r)\n        }\n    }()\n    fn = reflectx.ToFunc7x4(f)\n    return\n}","preventionTips":["Four outputs required — include every emitted collection plus error in the count","Update the converter alongside any 3->4 output refactor","Use typed MakeFunc7x4 for compile-time checks","Gate registrations behind construction-time smoke tests"],"tags":["go","apache-beam","reflection","function-arity","panic"],"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"}