{"record":{"id":"491fb0cabcb69fac","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-491fb0","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 5 inputs and 4 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 5 inputs and 4 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":1254,"sourceCode":"}\n\nfunc (c *shimFunc5x4) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc5x4) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc5x4) Call5x4(arg0, arg1, arg2, arg3, arg4 any) (any, any, any, any) {\n\tret := c.inner.Call([]any{arg0, arg1, arg2, arg3, arg4})\n\t_ = ret\n\treturn ret[0], ret[1], ret[2], ret[3]\n}\n\nfunc ToFunc5x4(c Func) Func5x4 {\n\tif c.Type().NumIn() != 5 || c.Type().NumOut() != 4 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 5 inputs and 4 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func5x4); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc5x4{inner: c}\n}\n\nfunc MakeFunc5x4(fn any) Func5x4 {\n\treturn ToFunc5x4(MakeFunc(fn))\n}\n\ntype Func6x0 interface {\n\tFunc\n\tCall6x0(any, any, any, any, any, any)\n}\n\ntype shimFunc6x0 struct {\n\tinner Func","sourceCodeStart":1236,"sourceCodeEnd":1272,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L1236-L1272","documentation":"reflectx.ToFunc5x4 wraps a reflectx.Func into a Func5x4 (5 inputs, 4 outputs). It panics with this message unless the func's reflect.Type has exactly 5 inputs and 4 outputs, because the shim unpacks four return values positionally.","triggerScenarios":"Calling reflectx.ToFunc5x4(c) where c.Type().NumIn() != 5 or c.Type().NumOut() != 4 — e.g. a multi-output DoFn emitting 3 values plus error (4 outputs but intended differently) or 4 values from the wrong input count.","commonSituations":"Complex fan-out DoFns whose output tuple grew/shrank during development; registering with the wrong fixed-arity wrapper; Go reflection surface mismatch after switching between func and DoFn struct styles.","solutions":["Make the function take 5 inputs and return exactly 4 values.","Choose the ToFuncN x M wrapper matching the actual signature.","Confirm the Beam registration (beam.ParDo / TryParDo) expects a 5x4 signature and adjust whichever side is wrong."],"exampleFix":"// before\nfunc fn(a A, b B, c C, d D, e E) (T, U, V) { ... }\nreflectx.ToFunc5x4(fn) // panics: 3 outputs\n\n// after\nfunc fn(a A, b B, c C, d D, e E) (Q, T, U, V) { ... }\nreflectx.ToFunc5x4(fn)","handlingStrategy":"validation","validationCode":"fn := reflect.TypeOf(fnAny)\nif fn.Kind() == reflect.Func && fn.NumIn() == 5 && fn.NumOut() == 4 {\n    _ = reflectx.ToFunc5x4(fnAny)\n}","typeGuard":"func isFunc5x4(f interface{}) bool {\n    t := reflect.TypeOf(f)\n    return t != nil && t.Kind() == reflect.Func && t.NumIn() == 5 && t.NumOut() == 4\n}","tryCatchPattern":"func safeToFunc5x4(c reflectx.Func) (f reflectx.Func5x4, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"ToFunc5x4 failed: %v\", r)\n        }\n    }()\n    return reflectx.ToFunc5x4(c), nil\n}","preventionTips":["Document each multi-output DoFn's exact signature next to its definition.","Run a pre-submission check that wraps all functions with their intended ToFunc helpers.","Keep emit-count and helper arity in sync during refactors.","Use DoFn structs to let Beam infer arity instead of hand-picking helpers."],"tags":["go","apache-beam","reflection","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"}