{"record":{"id":"4012306d914ddcf1","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-401230","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 6 inputs and 4 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 6 inputs and 4 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":1459,"sourceCode":"}\n\nfunc (c *shimFunc6x4) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc6x4) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc6x4) Call6x4(arg0, arg1, arg2, arg3, arg4, arg5 any) (any, any, any, any) {\n\tret := c.inner.Call([]any{arg0, arg1, arg2, arg3, arg4, arg5})\n\t_ = ret\n\treturn ret[0], ret[1], ret[2], ret[3]\n}\n\nfunc ToFunc6x4(c Func) Func6x4 {\n\tif c.Type().NumIn() != 6 || c.Type().NumOut() != 4 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 6 inputs and 4 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func6x4); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc6x4{inner: c}\n}\n\nfunc MakeFunc6x4(fn any) Func6x4 {\n\treturn ToFunc6x4(MakeFunc(fn))\n}\n\ntype Func7x0 interface {\n\tFunc\n\tCall7x0(any, any, any, any, any, any, any)\n}\n\ntype shimFunc7x0 struct {\n\tinner Func","sourceCodeStart":1441,"sourceCodeEnd":1477,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L1441-L1477","documentation":"reflectx.ToFunc6x4 wraps an arbitrary reflectx Func as a strongly-typed 6-input/4-output function. It panics when the wrapped function's reflect.Type does not have exactly 6 inputs and 4 outputs, because the generated shim cannot adapt an arity mismatch. This library uses panics for programmer errors detected at pipeline-graph construction time.","triggerScenarios":"Calling ToFunc6x4 (directly or via MakeFunc6x4) with a Func whose underlying Go signature has any number of inputs other than 6 or any number of outputs other than 4, e.g. wrapping a func(a,b,c,d,e any) (x,y,z any) (5 in, 3 out).","commonSituations":"DoFn methods or combinators registered with the wrong arity for the emitter/consumer being built; code changed from returning 3 values to 4 (e.g. adding an error) without updating the conversion; copy-paste of a ToFunc5x4-style registration where one parameter was forgotten; generics/type-parameter refactors changing the signature silently.","solutions":["Count the inputs and outputs of the function passed in and fix it to have exactly 6 parameters and 4 return values","If the function intentionally has a different arity, call the matching ToFuncNxM converter (e.g. ToFunc7x4) instead","If it should return fewer/more values, use a different FuncNxM target type or change the call site of the conversion","Recover from the panic in tests to surface the message, since it prints got/want arity and the func type"],"exampleFix":"// before\nf := reflectx.NewFunc(func(a, b, c, d, e any) (any, any, any) { ... })\nfn := reflectx.ToFunc6x4(f) // panics: 5 inputs, 3 outputs\n// after\nf := reflectx.NewFunc(func(a, b, c, d, e, f2 any) (any, any, any, any) { ... })\nfn := reflectx.ToFunc6x4(f)","handlingStrategy":"validation","validationCode":"t := f.Type()\nif t.NumIn() != 6 || t.NumOut() != 4 {\n    return fmt.Errorf(\"ToFunc6x4 needs 6 in / 4 out, got %d in / %d out (%v)\", t.NumIn(), t.NumOut(), t)\n}","typeGuard":"func isFunc6x4(f reflectx.Func) bool {\n    t := f.Type()\n    return t.NumIn() == 6 && t.NumOut() == 4\n}","tryCatchPattern":"func safeToFunc6x4(f reflectx.Func) (fn reflectx.Func6x4, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"conversion failed: %v\", r)\n        }\n    }()\n    fn = reflectx.ToFunc6x4(f)\n    return\n}","preventionTips":["Match converter choice to signature: NxM must equal the Go function's parameter and return counts","Re-run arity checks after every signature refactor","Prefer typed helpers (MakeFunc6x4 with a concrete Go func) so the compiler catches mismatches","Cover converter calls in unit tests so panics surface early"],"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"}