{"record":{"id":"9358d96d752eeffc","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-9358d9","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 1 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 2 inputs and 1 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":516,"sourceCode":"}\n\nfunc (c *shimFunc2x1) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc2x1) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc2x1) Call2x1(arg0, arg1 any) any {\n\tret := c.inner.Call([]any{arg0, arg1})\n\t_ = ret\n\treturn ret[0]\n}\n\nfunc ToFunc2x1(c Func) Func2x1 {\n\tif c.Type().NumIn() != 2 || c.Type().NumOut() != 1 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 1 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func2x1); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc2x1{inner: c}\n}\n\nfunc MakeFunc2x1(fn any) Func2x1 {\n\treturn ToFunc2x1(MakeFunc(fn))\n}\n\ntype Func2x2 interface {\n\tFunc\n\tCall2x2(any, any) (any, any)\n}\n\ntype shimFunc2x2 struct {\n\tinner Func","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L498-L534","documentation":"ToFunc2x1 adapts a generic reflectx Func into a Func2x1 (2 inputs, 1 output, a binary merge function). It panics unless the wrapped function has exactly 2 inputs and 1 output, catching signature mismatches at adaptation time.","triggerScenarios":"Calling reflectx.ToFunc2x1 with a Func whose Type().NumIn() != 2 or Type().NumOut() != 1, e.g. a combiner that also returns an error or takes a context.","commonSituations":"Merge/combine functions refactored to return (V, error); passing a 1-input function to a 2-input helper; wrong MakeFuncNxM variant chosen.","solutions":["Make the function take exactly 2 inputs and return exactly 1 value.","Pick the matching arity variant.","Check NumIn()/NumOut() on the Func's type first."],"exampleFix":"// before\nreflectx.MakeFunc2x1(func(a, b int) (int, error) { return a + b, nil }) // panics\n// after\nreflectx.MakeFunc2x1(func(a, b int) int { return a + b })","handlingStrategy":"validation","validationCode":"t := c.Type()\nif t.NumIn() != 2 || t.NumOut() != 1 {\n    return fmt.Errorf(\"func %v has %d ins/%d outs; ToFunc2x1 needs 2 ins/1 out\", t, t.NumIn(), t.NumOut())\n}","typeGuard":"func isFunc2x1(c reflectx.Func) bool {\n    return c.Type().NumIn() == 2 && c.Type().NumOut() == 1\n}","tryCatchPattern":"func safeToFunc2x1(c reflectx.Func) (f reflectx.Func2x1) {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Fatalf(\"ToFunc2x1 arity mismatch: %v\", r)\n        }\n    }()\n    return reflectx.ToFunc2x1(c)\n}","preventionTips":["Merge/combine functions should not return errors in this API; handle errors outside the wrapper.","Verify both inputs exist when adapting from 1x1 to 2x1.","Keep a test that builds all combiners at init."],"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"}