{"record":{"id":"ca9b785b4a39b092","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-ca9b78","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 0 inputs and 4 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 0 inputs and 4 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":229,"sourceCode":"}\n\nfunc (c *shimFunc0x4) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc0x4) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc0x4) Call0x4() (any, any, any, any) {\n\tret := c.inner.Call([]any{})\n\t_ = ret\n\treturn ret[0], ret[1], ret[2], ret[3]\n}\n\nfunc ToFunc0x4(c Func) Func0x4 {\n\tif c.Type().NumIn() != 0 || c.Type().NumOut() != 4 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 0 inputs and 4 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func0x4); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc0x4{inner: c}\n}\n\nfunc MakeFunc0x4(fn any) Func0x4 {\n\treturn ToFunc0x4(MakeFunc(fn))\n}\n\ntype Func1x0 interface {\n\tFunc\n\tCall1x0(any)\n}\n\ntype shimFunc1x0 struct {\n\tinner Func","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L211-L247","documentation":"ToFunc0x4 adapts a generic reflectx Func into a Func0x4 (0 inputs, 4 outputs). It panics when the wrapped function's reflect type does not have exactly 0 inputs and 4 outputs. The library throws this eagerly so arity mismatches fail at wrapper-construction time instead of silently failing at call time.","triggerScenarios":"Calling reflectx.ToFunc0x4 (directly or via MakeFunc0x4) with a Func whose Type().NumIn() != 0 or Type().NumOut() != 4, e.g. wrapping a function that takes context parameters or returns fewer/more than 4 values.","commonSituations":"Hand-writing a DoFn emit function after changing its return count; passing a registered function whose signature was refactored (added an error return or input) while the MakeFunc0x4 call site was not updated; copy-pasting adapter code between arities.","solutions":["Change the wrapped function to have exactly 0 inputs and 4 outputs, or update the call to the ToFunc/MakeFunc variant matching the actual arity (e.g. ToFunc1x4 if it takes 1 input).","Check c.Type() with NumIn()/NumOut() before wrapping and pick the correct FuncN type.","If the function needs different arity, register it with the matching MakeFuncNxM helper generated in calls.go."],"exampleFix":"// before\nf := reflectx.MakeFunc0x4(func() (int, int, int) { ... }) // panics: 3 outputs, want 4\n// after\nf := reflectx.MakeFunc0x4(func() (int, int, int, int) { return 1, 2, 3, 4 })","handlingStrategy":"validation","validationCode":"t := c.Type()\nif t.NumIn() != 0 || t.NumOut() != 4 {\n    panic(fmt.Sprintf(\"func %v has %d ins/%d outs; ToFunc0x4 needs 0 ins/4 outs\", t, t.NumIn(), t.NumOut()))\n}","typeGuard":"func isFunc0x4(c reflectx.Func) bool {\n    return c.Type().NumIn() == 0 && c.Type().NumOut() == 4\n}","tryCatchPattern":"func safeToFunc0x4(c reflectx.Func) (f reflectx.Func0x4) {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Fatalf(\"ToFunc0x4 arity mismatch: %v\", r)\n        }\n    }()\n    return reflectx.ToFunc0x4(c)\n}","preventionTips":["Derive the MakeFuncNxM call from the function literal's actual signature, not the other way around.","Re-run unit tests that exercise the wrapper after every signature change.","Add a small table test asserting NumIn/NumOut for every registered function."],"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"}