{"record":{"id":"cfb3a6bd5205f90a","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-cfb3a6","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 3 inputs and 3 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 3 inputs and 3 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":803,"sourceCode":"}\n\nfunc (c *shimFunc3x3) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc3x3) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc3x3) Call3x3(arg0, arg1, arg2 any) (any, any, any) {\n\tret := c.inner.Call([]any{arg0, arg1, arg2})\n\t_ = ret\n\treturn ret[0], ret[1], ret[2]\n}\n\nfunc ToFunc3x3(c Func) Func3x3 {\n\tif c.Type().NumIn() != 3 || c.Type().NumOut() != 3 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 3 inputs and 3 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func3x3); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc3x3{inner: c}\n}\n\nfunc MakeFunc3x3(fn any) Func3x3 {\n\treturn ToFunc3x3(MakeFunc(fn))\n}\n\ntype Func3x4 interface {\n\tFunc\n\tCall3x4(any, any, any) (any, any, any, any)\n}\n\ntype shimFunc3x4 struct {\n\tinner Func","sourceCodeStart":785,"sourceCodeEnd":821,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L785-L821","documentation":"reflectx.ToFunc3x3 converts a generic Func to a strongly-typed Func3x3 (3 inputs, 3 outputs). It panics when the underlying reflect.Type's NumIn() is not 3 or NumOut() is not 3. Beam throws this at conversion time so that the reflection shim's fixed return count matches the wrapped function; a mismatch would otherwise surface as an index-out-of-range or wrong-value bug deep inside the runner.","triggerScenarios":"Calling reflectx.ToFunc3x3(f) where f.Type().NumIn() != 3 (e.g. 2 or 4 params) or f.Type().NumOut() != 3 (e.g. 2 or 4 return values).","commonSituations":"Multi-output functions that were extended to return an extra diagnostic value (4 outputs), or trimmed to drop an output (2 outputs), during schema/PCollection changes; also hitting the wrong converter after copy-pasting a ToFuncNxM call for a function with different arity.","solutions":["Make the function take exactly 3 parameters and return exactly 3 values.","Use the converter matching the real arity: ToFunc3x2 or ToFunc3x4 for 2/4 outputs.","Check with reflect.TypeOf(fn).NumIn()/NumOut() before wrapping.","If the function is part of a beam.DoFn path, prefer the typed DoFn registration API so signature matching is done by Beam's machinery instead of manual reflectx coercion."],"exampleFix":"// before\nf := reflectx.ToFunc3x3(func(a int, b, c string) (int, string, bool, error) { return a, b, true, nil }) // 4 outputs, panics\n// after\nf := reflectx.ToFunc3x4(func(a int, b, c string) (int, string, bool, error) { return a, b, true, nil })","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(fn)\nif t.NumIn() != 3 || t.NumOut() != 3 {\n    panic(fmt.Sprintf(\"expected 3-in/3-out func, got %v (%d in, %d out)\", t, t.NumIn(), t.NumOut()))\n}\nf := reflectx.ToFunc3x3(f)","typeGuard":"func isFunc3x3(fn any) bool {\n    t := reflect.TypeOf(fn)\n    return t != nil && t.Kind() == reflect.Func && t.NumIn() == 3 && t.NumOut() == 3\n}","tryCatchPattern":"func safeToFunc3x3(f reflectx.Func) (out reflectx.Func3x3, err error) {\n    defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"ToFunc3x3: %v\", r) } }()\n    out = reflectx.ToFunc3x3(f)\n    return\n}","preventionTips":["Re-verify arity after any schema/PCollection change that adds or removes outputs.","Include (T, T, error) counting discipline in code review checklists.","Write table-driven tests that assert NumIn/NumOut for each converter target.","Wrap converters in small typed helpers so the compiler and one assertion site cover many call sites."],"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"}