{"record":{"id":"3b5a91cdcb1dbe49","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-3b5a91","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 4 inputs and 0 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 4 inputs and 0 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":885,"sourceCode":"}\n\nfunc (c *shimFunc4x0) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc4x0) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc4x0) Call4x0(arg0, arg1, arg2, arg3 any) {\n\tret := c.inner.Call([]any{arg0, arg1, arg2, arg3})\n\t_ = ret\n\treturn\n}\n\nfunc ToFunc4x0(c Func) Func4x0 {\n\tif c.Type().NumIn() != 4 || c.Type().NumOut() != 0 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 4 inputs and 0 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func4x0); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc4x0{inner: c}\n}\n\nfunc MakeFunc4x0(fn any) Func4x0 {\n\treturn ToFunc4x0(MakeFunc(fn))\n}\n\ntype Func4x1 interface {\n\tFunc\n\tCall4x1(any, any, any, any) any\n}\n\ntype shimFunc4x1 struct {\n\tinner Func","sourceCodeStart":867,"sourceCodeEnd":903,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L867-L903","documentation":"reflectx.ToFunc4x0 converts a generic Func to a strongly-typed Func4x0 (4 inputs, 0 outputs). It panics if the underlying reflect.Type does not have exactly NumIn()==4 and NumOut()==0. Beam throws this to guarantee the fixed-arity shim's invocation contract matches the wrapped function, catching the mismatch at conversion time with the actual type in the message.","triggerScenarios":"Calling reflectx.ToFunc4x0(f) where f.Type().NumIn() != 4 (e.g. 3 or 5 params) or f.Type().NumOut() != 0 (the function returns anything, including an error).","commonSituations":"Sink-style 4-argument functions that still return an error value, functions that gained or lost a context/emitter parameter during refactoring, or copy-pasted converter calls pointing at the wrong arity variant.","solutions":["Make the function take exactly 4 parameters and return nothing.","If it returns a value or error, switch to the matching converter (ToFunc4x1, ToFunc4x2, ...).","Confirm the shape with reflect.TypeOf(fn).NumIn()/NumOut() before wrapping.","Move the error handling inside the function body (log/emit) if a no-output signature is required by the pipeline."],"exampleFix":"// before\nf := reflectx.ToFunc4x0(func(a int, b string, c bool, d float64) error { return nil }) // 1 output, panics\n// after\nf := reflectx.ToFunc4x0(func(a int, b string, c bool, d float64) {\n    // handle a,b,c,d without returning\n})","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(fn)\nif t.NumIn() != 4 || t.NumOut() != 0 {\n    panic(fmt.Sprintf(\"expected 4-in/0-out func, got %v (%d in, %d out)\", t, t.NumIn(), t.NumOut()))\n}\nf := reflectx.ToFunc4x0(f)","typeGuard":"func isFunc4x0(fn any) bool {\n    t := reflect.TypeOf(fn)\n    return t != nil && t.Kind() == reflect.Func && t.NumIn() == 4 && t.NumOut() == 0\n}","tryCatchPattern":"func safeToFunc4x0(f reflectx.Func) (out reflectx.Func4x0, err error) {\n    defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"ToFunc4x0: %v\", r) } }()\n    out = reflectx.ToFunc4x0(f)\n    return\n}","preventionTips":["Make consumer/sink functions truly return-free; log or emit errors internally.","Assert NumIn/NumOut in unit tests for every ToFunc4x0 target.","Change parameter count and converter call in the same commit.","Use closures for auxiliary state instead of extra parameters."],"tags":["go","apache-beam","reflection","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"}