{"record":{"id":"20a523bd68cbef74","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-20a523","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 3 inputs and 0 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 3 inputs and 0 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":680,"sourceCode":"}\n\nfunc (c *shimFunc3x0) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc3x0) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc3x0) Call3x0(arg0, arg1, arg2 any) {\n\tret := c.inner.Call([]any{arg0, arg1, arg2})\n\t_ = ret\n\treturn\n}\n\nfunc ToFunc3x0(c Func) Func3x0 {\n\tif c.Type().NumIn() != 3 || c.Type().NumOut() != 0 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 3 inputs and 0 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func3x0); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc3x0{inner: c}\n}\n\nfunc MakeFunc3x0(fn any) Func3x0 {\n\treturn ToFunc3x0(MakeFunc(fn))\n}\n\ntype Func3x1 interface {\n\tFunc\n\tCall3x1(any, any, any) any\n}\n\ntype shimFunc3x1 struct {\n\tinner Func","sourceCodeStart":662,"sourceCodeEnd":698,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L662-L698","documentation":"reflectx.ToFunc3x0 converts a generic Func to a strongly-typed Func3x0 (3 inputs, 0 outputs). It panics when the underlying reflect.Type's NumIn() is not 3 or NumOut() is not 0. The Beam SDK does this to guarantee that reflection-based invocation inside the pipeline can supply exactly the expected arguments and consume no return values, failing fast with the actual type printed in the message.","triggerScenarios":"Calling reflectx.ToFunc3x0(f) where f.Type().NumIn() != 3 (e.g. 2 or 4 params) or f.Type().NumOut() != 0 (the function returns 1+ values, such as an error).","commonSituations":"Wrapping a sink-style function that accidentally returns a value or error, registering a function with an extra context/emitter parameter added during refactoring, or pointing at the wrong converter for a 3-input function that actually returns results (should be ToFunc3x1 or higher).","solutions":["Make the wrapped function take exactly 3 parameters and return nothing (no error return).","If the function must return values or an error, use the appropriate converter such as ToFunc3x1/ToFunc3x2.","Verify the function's signature with reflect.TypeOf(fn).NumIn()/NumOut() before wrapping.","If extra params are unwanted, close over them in the enclosing scope so the func literal itself has exactly 3 declared parameters."],"exampleFix":"// before\nf := reflectx.ToFunc3x0(func(key string, val int, emit func(int)) error { return nil }) // returns error, panics\n// after\nf := reflectx.ToFunc3x0(func(key string, val int, emit func(int)) {\n    emit(val)\n})","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(fn)\nif t.NumIn() != 3 || t.NumOut() != 0 {\n    panic(fmt.Sprintf(\"expected 3-in/0-out func, got %v (%d in, %d out)\", t, t.NumIn(), t.NumOut()))\n}\nf := reflectx.ToFunc3x0(f)","typeGuard":"func isFunc3x0(fn any) bool {\n    t := reflect.TypeOf(fn)\n    return t != nil && t.Kind() == reflect.Func && t.NumIn() == 3 && t.NumOut() == 0\n}","tryCatchPattern":"func safeToFunc3x0(f reflectx.Func) (out reflectx.Func3x0, err error) {\n    defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"ToFunc3x0: %v\", r) } }()\n    out = reflectx.ToFunc3x0(f)\n    return\n}","preventionTips":["Keep sink-style functions return-free; handle errors inside the body instead of returning them.","Add a signature assertion test for each function wrapped with ToFunc3x0.","Drop leftover (T, error) returns when converting a mapper into a consumer.","Close over extra state instead of adding parameters that change the arity."],"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"}