{"record":{"id":"9843ed50414a75da","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-9843ed","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 3 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 2 inputs and 3 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":598,"sourceCode":"}\n\nfunc (c *shimFunc2x3) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc2x3) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc2x3) Call2x3(arg0, arg1 any) (any, any, any) {\n\tret := c.inner.Call([]any{arg0, arg1})\n\t_ = ret\n\treturn ret[0], ret[1], ret[2]\n}\n\nfunc ToFunc2x3(c Func) Func2x3 {\n\tif c.Type().NumIn() != 2 || c.Type().NumOut() != 3 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 3 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func2x3); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc2x3{inner: c}\n}\n\nfunc MakeFunc2x3(fn any) Func2x3 {\n\treturn ToFunc2x3(MakeFunc(fn))\n}\n\ntype Func2x4 interface {\n\tFunc\n\tCall2x4(any, any) (any, any, any, any)\n}\n\ntype shimFunc2x4 struct {\n\tinner Func","sourceCodeStart":580,"sourceCodeEnd":616,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L580-L616","documentation":"ToFunc2x3 adapts a generic reflectx Func into a Func2x3 (2 inputs, 3 outputs). It panics when the wrapped function's type does not have exactly 2 inputs and 3 outputs, so arity errors fail fast at wrapper construction.","triggerScenarios":"Calling reflectx.ToFunc2x3 with a Func whose Type().NumIn() != 2 or Type().NumOut() != 3.","commonSituations":"Functions with 2 inputs whose return count changed; mis-selecting among the generated NxM helpers in calls.go after adding or removing a return value.","solutions":["Make the function take 2 inputs and return exactly 3 values.","Switch to the ToFunc/MakeFuncNxM variant matching the actual signature.","Check c.Type().NumIn()==2 && c.Type().NumOut()==3 before wrapping."],"exampleFix":"// before\nreflectx.MakeFunc2x3(func(a, b int) (int, int) { return a, b }) // panics: 2 outputs\n// after\nreflectx.MakeFunc2x3(func(a, b int) (int, int, int) { return a, b, a + b })","handlingStrategy":"validation","validationCode":"t := c.Type()\nif t.NumIn() != 2 || t.NumOut() != 3 {\n    return fmt.Errorf(\"func %v has %d ins/%d outs; ToFunc2x3 needs 2 ins/3 outs\", t, t.NumIn(), t.NumOut())\n}","typeGuard":"func isFunc2x3(c reflectx.Func) bool {\n    return c.Type().NumIn() == 2 && c.Type().NumOut() == 3\n}","tryCatchPattern":"func safeToFunc2x3(c reflectx.Func) (f reflectx.Func2x3) {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Fatalf(\"ToFunc2x3 arity mismatch: %v\", r)\n        }\n    }()\n    return reflectx.ToFunc2x3(c)\n}","preventionTips":["Count the return tuple before choosing the MakeFuncNxM variant.","Keep function literals and their adapter calls in the same file/commit.","Add arity assertions for every wrapper at startup."],"tags":["go","reflection","arity-mismatch","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-20T03:17:13.778Z"}