{"record":{"id":"cb758e178e172947","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 0 inputs and 0 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 0 inputs and 0 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":65,"sourceCode":"}\n\nfunc (c *shimFunc0x0) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc0x0) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc0x0) Call0x0() {\n\tret := c.inner.Call([]any{})\n\t_ = ret\n\treturn\n}\n\nfunc ToFunc0x0(c Func) Func0x0 {\n\tif c.Type().NumIn() != 0 || c.Type().NumOut() != 0 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 0 inputs and 0 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func0x0); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc0x0{inner: c}\n}\n\nfunc MakeFunc0x0(fn any) Func0x0 {\n\treturn ToFunc0x0(MakeFunc(fn))\n}\n\ntype Func0x1 interface {\n\tFunc\n\tCall0x1() any\n}\n\ntype shimFunc0x1 struct {\n\tinner Func","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L47-L83","documentation":"reflectx.ToFunc0x0 adapts a generic reflectx.Func to a Func0x0 (no inputs, no outputs) and panics if the underlying reflect function type does not have exactly 0 inputs and 0 outputs. The message includes the actual func type and its input/output counts.","triggerScenarios":"Calling ToFunc0x0 or MakeFunc0x0 with a Func whose reflect type has any inputs or any outputs, e.g. a func(int) or func() error.","commonSituations":"Wrapping a DoFn-style method that returns an error or takes a context into a zero-arity shim; auto-registering functions by reflection where arity was not checked first.","solutions":["Use the ToFunc/MakeFunc variant matching the real arity, e.g. ToFunc1x1 for func(T) T or ToFunc0x1 for func() T.","Change the function to genuinely take no inputs and return nothing.","If arity is dynamic, check fn.Type().NumIn()/NumOut() and dispatch to the right adapter before calling."],"exampleFix":"// before\nreflectx.ToFunc0x0(reflectx.MakeFunc(func(ctx context.Context) error { ... }))\n// after\nreflectx.ToFunc1x1(reflectx.MakeFunc(fn)) // or make fn truly func(){}","handlingStrategy":"validation","validationCode":"func isFunc0x0(fn reflectx.Func) bool {\n    return fn.Type().NumIn() == 0 && fn.Type().NumOut() == 0\n}","typeGuard":"func asFunc0x0(fn reflectx.Func) (reflectx.Func0x0, bool) {\n    if f, ok := fn.(reflectx.Func0x0); ok { return f, true }\n    return nil, false\n}","tryCatchPattern":"func safeToFunc0x0(fn reflectx.Func) (f reflectx.Func0x0, err error) {\n    defer func() {\n        if r := recover(); r != nil { err = fmt.Errorf(\"ToFunc0x0: %v\", r) }\n    }()\n    return reflectx.ToFunc0x0(fn), nil\n}","preventionTips":["Match the ToFuncNxx adapter to the function's real arity.","Check NumIn/NumOut on the reflect type before adapting.","Avoid wrapping functions that return error into zero-output shims."],"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"}