{"record":{"id":"b6adfa9ec6e19507","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-b6adfa","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 0 inputs and 2 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 0 inputs and 2 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":147,"sourceCode":"}\n\nfunc (c *shimFunc0x2) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc0x2) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc0x2) Call0x2() (any, any) {\n\tret := c.inner.Call([]any{})\n\t_ = ret\n\treturn ret[0], ret[1]\n}\n\nfunc ToFunc0x2(c Func) Func0x2 {\n\tif c.Type().NumIn() != 0 || c.Type().NumOut() != 2 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 0 inputs and 2 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func0x2); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc0x2{inner: c}\n}\n\nfunc MakeFunc0x2(fn any) Func0x2 {\n\treturn ToFunc0x2(MakeFunc(fn))\n}\n\ntype Func0x3 interface {\n\tFunc\n\tCall0x3() (any, any, any)\n}\n\ntype shimFunc0x3 struct {\n\tinner Func","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L129-L165","documentation":"reflectx.ToFunc0x2 adapts a Func to Func0x2 (0 inputs, 2 outputs) and panics unless the reflect type has exactly 0 inputs and 2 outputs. The panic message reports the actual function type with its input and output counts.","triggerScenarios":"Calling ToFunc0x2 or MakeFunc0x2 with a func whose signature is not func() (A, B) — e.g. func() (A, B, C) (three returns) or func(x A) (B, C) (one input).","commonSituations":"Adapting a supplier that returns value plus two auxiliaries (e.g. (T, metadata, error)); adding a context parameter to an existing 0x2 function without switching adapters.","solutions":["Use ToFunc0x3 (or the matching N-output adapter) if the function returns three values.","Remove extra inputs so the signature is exactly func() (A, B).","Compute NumIn/NumOut from the reflect type and select the adapter programmatically before invoking."],"exampleFix":"// before\nreflectx.ToFunc0x2(reflectx.MakeFunc(func() (int, int, error) { ... }))\n// after\nreflectx.ToFunc0x3(reflectx.MakeFunc(func() (int, int, error) { ... }))","handlingStrategy":"validation","validationCode":"func isFunc0x2(fn reflectx.Func) bool {\n    return fn.Type().NumIn() == 0 && fn.Type().NumOut() == 2\n}","typeGuard":"func asFunc0x2(fn reflectx.Func) (reflectx.Func0x2, bool) {\n    if f, ok := fn.(reflectx.Func0x2); ok { return f, true }\n    return nil, false\n}","tryCatchPattern":"func safeToFunc0x2(fn reflectx.Func) (f reflectx.Func0x2, err error) {\n    defer func() {\n        if r := recover(); r != nil { err = fmt.Errorf(\"ToFunc0x2: %v\", r) }\n    }()\n    return reflectx.ToFunc0x2(fn), nil\n}","preventionTips":["Verify the function returns exactly two values and takes none.","Re-check the adapter choice after any signature change.","Dispatch on NumIn/NumOut when arity is determined at runtime."],"tags":["go","apache-beam","reflectx","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-20T03:17:13.778Z"}