{"record":{"id":"03868318aab0ce8d","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-038683","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 0 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 2 inputs and 0 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":475,"sourceCode":"}\n\nfunc (c *shimFunc2x0) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc2x0) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc2x0) Call2x0(arg0, arg1 any) {\n\tret := c.inner.Call([]any{arg0, arg1})\n\t_ = ret\n\treturn\n}\n\nfunc ToFunc2x0(c Func) Func2x0 {\n\tif c.Type().NumIn() != 2 || c.Type().NumOut() != 0 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 2 inputs and 0 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func2x0); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc2x0{inner: c}\n}\n\nfunc MakeFunc2x0(fn any) Func2x0 {\n\treturn ToFunc2x0(MakeFunc(fn))\n}\n\ntype Func2x1 interface {\n\tFunc\n\tCall2x1(any, any) any\n}\n\ntype shimFunc2x1 struct {\n\tinner Func","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L457-L493","documentation":"ToFunc2x0 adapts a generic reflectx Func into a Func2x0 (2 inputs, 0 outputs, a binary consumer). It panics when the wrapped function's type does not have exactly 2 inputs and 0 outputs, so arity mismatches fail at construction rather than at call time.","triggerScenarios":"Calling reflectx.ToFunc2x0 (or its MakeFunc2x0 helper) with a Func whose Type().NumIn() != 2 or Type().NumOut() != 0, e.g. a one-argument sink or one that returns a value.","commonSituations":"Writing a combine/sink function that lost or gained a parameter; wrapping a function that still returns an error; using the wrong helper variant after a signature change.","solutions":["Make the wrapped function take exactly 2 inputs and return nothing.","Use the ToFunc/MakeFuncNxM variant matching the actual signature.","Verify c.Type().NumIn()==2 && c.Type().NumOut()==0 before wrapping."],"exampleFix":"// before\nreflectx.MakeFunc2x0(func(a, b int) int { return a + b }) // panics: 1 output\n// after\nreflectx.MakeFunc2x0(func(a, b int) { _ = a + b })","handlingStrategy":"validation","validationCode":"t := c.Type()\nif t.NumIn() != 2 || t.NumOut() != 0 {\n    return fmt.Errorf(\"func %v has %d ins/%d outs; ToFunc2x0 needs 2 ins/0 outs\", t, t.NumIn(), t.NumOut())\n}","typeGuard":"func isFunc2x0(c reflectx.Func) bool {\n    return c.Type().NumIn() == 2 && c.Type().NumOut() == 0\n}","tryCatchPattern":"func safeToFunc2x0(c reflectx.Func) (f reflectx.Func2x0) {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Fatalf(\"ToFunc2x0 arity mismatch: %v\", r)\n        }\n    }()\n    return reflectx.ToFunc2x0(c)\n}","preventionTips":["Sinks must return nothing; strip error returns or switch to a variant with outputs.","Check parameter count when converting a 1-input consumer to a 2-input one.","Assert arity in tests for all sink wrappers."],"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"}