{"record":{"id":"905880f6ef73aaea","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-905880","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 2 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 2 inputs and 2 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":557,"sourceCode":"}\n\nfunc (c *shimFunc2x2) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc2x2) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc2x2) Call2x2(arg0, arg1 any) (any, any) {\n\tret := c.inner.Call([]any{arg0, arg1})\n\t_ = ret\n\treturn ret[0], ret[1]\n}\n\nfunc ToFunc2x2(c Func) Func2x2 {\n\tif c.Type().NumIn() != 2 || c.Type().NumOut() != 2 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 2 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func2x2); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc2x2{inner: c}\n}\n\nfunc MakeFunc2x2(fn any) Func2x2 {\n\treturn ToFunc2x2(MakeFunc(fn))\n}\n\ntype Func2x3 interface {\n\tFunc\n\tCall2x3(any, any) (any, any, any)\n}\n\ntype shimFunc2x3 struct {\n\tinner Func","sourceCodeStart":539,"sourceCodeEnd":575,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L539-L575","documentation":"ToFunc2x2 adapts a generic reflectx Func into a Func2x2 (2 inputs, 2 outputs). It panics when the wrapped function's reflect type does not have exactly 2 inputs and 2 outputs, surfacing the mismatch when the wrapper is created.","triggerScenarios":"Calling reflectx.ToFunc2x2 with a Func whose Type().NumIn() != 2 or Type().NumOut() != 2.","commonSituations":"Binary functions updated to return an extra value; copy-pasted adapter calls between arity variants; merge functions whose signature changed during refactoring.","solutions":["Make the function take 2 inputs and return exactly 2 values.","Use the ToFunc/MakeFuncNxM variant matching the real arity.","Validate NumIn()/NumOut() before adapting."],"exampleFix":"// before\nreflectx.MakeFunc2x2(func(a, b int) int { return a + b }) // panics: 1 output\n// after\nreflectx.MakeFunc2x2(func(a, b int) (int, int) { return a + b, a - b })","handlingStrategy":"validation","validationCode":"t := c.Type()\nif t.NumIn() != 2 || t.NumOut() != 2 {\n    return fmt.Errorf(\"func %v has %d ins/%d outs; ToFunc2x2 needs 2 ins/2 outs\", t, t.NumIn(), t.NumOut())\n}","typeGuard":"func isFunc2x2(c reflectx.Func) bool {\n    return c.Type().NumIn() == 2 && c.Type().NumOut() == 2\n}","tryCatchPattern":"func safeToFunc2x2(c reflectx.Func) (f reflectx.Func2x2) {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Fatalf(\"ToFunc2x2 arity mismatch: %v\", r)\n        }\n    }()\n    return reflectx.ToFunc2x2(c)\n}","preventionTips":["Match inputs and outputs counts explicitly when writing 2x2 functions.","Update variant selection whenever a return value is added or removed.","Include wrapper construction in CI tests."],"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"}