{"record":{"id":"5092194dbed83ee1","repo":"apache/beam","slug":"incompatible-func-type-got-func-v-with-v-inputs-and-v-calls","errorCode":null,"errorMessage":"Incompatible func type: got func %v with %v inputs and %v outputs, want 0 inputs and 1 outputs","messagePattern":"Incompatible func type: got func (.+?) with (.+?) inputs and (.+?) outputs, want 0 inputs and 1 outputs","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/calls.go","lineNumber":106,"sourceCode":"}\n\nfunc (c *shimFunc0x1) Type() reflect.Type {\n\treturn c.inner.Type()\n}\n\nfunc (c *shimFunc0x1) Call(args []any) []any {\n\treturn c.inner.Call(args)\n}\n\nfunc (c *shimFunc0x1) Call0x1() any {\n\tret := c.inner.Call([]any{})\n\t_ = ret\n\treturn ret[0]\n}\n\nfunc ToFunc0x1(c Func) Func0x1 {\n\tif c.Type().NumIn() != 0 || c.Type().NumOut() != 1 {\n\t\tpanic(fmt.Sprintf(\"Incompatible func type: got func %v with %v inputs and %v outputs, want 0 inputs and 1 outputs\", c.Type(), c.Type().NumIn(), c.Type().NumOut()))\n\t}\n\tif sc, ok := c.(Func0x1); ok {\n\t\treturn sc\n\t}\n\treturn &shimFunc0x1{inner: c}\n}\n\nfunc MakeFunc0x1(fn any) Func0x1 {\n\treturn ToFunc0x1(MakeFunc(fn))\n}\n\ntype Func0x2 interface {\n\tFunc\n\tCall0x2() (any, any)\n}\n\ntype shimFunc0x2 struct {\n\tinner Func","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/calls.go#L88-L124","documentation":"reflectx.ToFunc0x1 adapts a Func to Func0x1 (0 inputs, 1 output) and panics unless the reflect type has exactly 0 inputs and 1 output. The panic message reports the actual function type, input count and output count.","triggerScenarios":"Calling ToFunc0x1 or MakeFunc0x1 with a func that has inputs (e.g. func(int) int) or the wrong number of returns (e.g. func() (T, error)).","commonSituations":"Trying to adapt a supplier that returns (value, error) — the error second return makes NumOut()==2 and trips the check; passing a mapper function expecting an element argument.","solutions":["Match the adapter to the signature: for (value, error) returns use a 0x2 adapter, for func(T) T use ToFunc1x1.","Drop the error return or handle it inside the function body so the signature is func() T.","Inspect fn.Type().NumIn()/NumOut() at runtime and choose the correct ToFuncNxx variant."],"exampleFix":"// before\nreflectx.ToFunc0x1(reflectx.MakeFunc(func() (int, error) { ... }))\n// after\nreflectx.ToFunc0x2(reflectx.MakeFunc(func() (int, error) { ... }))","handlingStrategy":"validation","validationCode":"func isFunc0x1(fn reflectx.Func) bool {\n    return fn.Type().NumIn() == 0 && fn.Type().NumOut() == 1\n}","typeGuard":"func asFunc0x1(fn reflectx.Func) (reflectx.Func0x1, bool) {\n    if f, ok := fn.(reflectx.Func0x1); ok { return f, true }\n    return nil, false\n}","tryCatchPattern":"func safeToFunc0x1(fn reflectx.Func) (f reflectx.Func0x1, err error) {\n    defer func() {\n        if r := recover(); r != nil { err = fmt.Errorf(\"ToFunc0x1: %v\", r) }\n    }()\n    return reflectx.ToFunc0x1(fn), nil\n}","preventionTips":["Remember (T, error) counts as 2 outputs — use the 0x2 adapter.","Assert signature with reflection before wrapping.","Keep suppliers free of extra parameters."],"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"}