{"record":{"id":"79e998de2d272607","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-79e998","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 1 inputs and 4 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 1 inputs and 4 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":434,"sourceCode":"}\n\nfunc (c *shimFunc1x4) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc1x4) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc1x4) Call1x4(arg0 any) (any, any, any, any) {\n\tret := c.inner.Call([]any{arg0})\n\t_ = ret\n\treturn ret[0], ret[1], ret[2], ret[3]\n}\n\nfunc ToFunc1x4(c Func) Func1x4 {\n\tif c.Type().NumIn() != 1 || c.Type().NumOut() != 4 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 1 inputs and 4 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func1x4); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc1x4{inner: c}\n}\n\nfunc MakeFunc1x4(fn any) Func1x4 {\n\treturn ToFunc1x4(MakeFunc(fn))\n}\n\ntype Func2x0 interface {\n\tFunc\n\tCall2x0(any, any)\n}\n\ntype shimFunc2x0 struct {\n\tinner Func","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L416-L452","documentation":"ToFunc1x4 adapts a generic reflectx Func into a Func1x4 (1 input, 4 outputs). It panics when the wrapped function's type does not have exactly 1 input and 4 outputs. The guard ensures arity errors are caught when the wrapper is built.","triggerScenarios":"Calling reflectx.ToFunc1x4 or MakeFunc1x4 with a Func whose Type().NumIn() != 1 or Type().NumOut() != 4.","commonSituations":"Wrapping a function with a different return count after refactoring; mis-selecting the generated helper among the NxM variants in calls.go.","solutions":["Make the wrapped function take 1 input and return exactly 4 values.","Switch to the matching arity variant (e.g. ToFunc1x3).","Assert c.Type().NumIn()==1 && c.Type().NumOut()==4 before wrapping."],"exampleFix":"// before\nreflectx.MakeFunc1x4(func(x int) (int, int, int) { return x, x, x }) // panics\n// after\nreflectx.MakeFunc1x4(func(x int) (int, int, int, int) { return x, x, x, x })","handlingStrategy":"validation","validationCode":"t := c.Type()\nif t.NumIn() != 1 || t.NumOut() != 4 {\n    return fmt.Errorf(\"func %v has %d ins/%d outs; ToFunc1x4 needs 1 in/4 outs\", t, t.NumIn(), t.NumOut())\n}","typeGuard":"func isFunc1x4(c reflectx.Func) bool {\n    return c.Type().NumIn() == 1 && c.Type().NumOut() == 4\n}","tryCatchPattern":"func safeToFunc1x4(c reflectx.Func) (f reflectx.Func1x4) {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Fatalf(\"ToFunc1x4 arity mismatch: %v\", r)\n        }\n    }()\n    return reflectx.ToFunc1x4(c)\n}","preventionTips":["After any change to a wrapped function's returns, update the MakeFuncNxM variant in the same change.","Avoid hand-edited arity in copy-pasted adapter code; regenerate from the function signature.","Add startup-time construction 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"}