{"record":{"id":"1b1fc485d9cf266b","repo":"apache/beam","slug":"failed-to-optimize-createaccumulator-for-combiner-v-failed","errorCode":null,"errorMessage":"Failed to optimize CreateAccumulator for combiner %v. Failed to infer types","messagePattern":"Failed to optimize CreateAccumulator for combiner (.+?)\\. Failed to infer types","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/register/register.go","lineNumber":7924,"sourceCode":"\t\t\treturn reflectx.MakeFunc(func() (T0, error) {\n\t\t\t\treturn fn.(createAccumulator0x2[T0]).CreateAccumulator()\n\t\t\t})\n\t\t}\n\t} else if _, ok := accum.(createAccumulator0x1[T0]); ok {\n\t\tcaller := func(fn any) reflectx.Func {\n\t\t\tf := fn.(func() T0)\n\t\t\treturn &caller0x1[T0]{fn: f}\n\t\t}\n\t\treflectx.RegisterFunc(reflect.TypeOf((*func() T0)(nil)).Elem(), caller)\n\n\t\tcreateAccumulatorWrapper = func(fn any) reflectx.Func {\n\t\t\treturn reflectx.MakeFunc(func() T0 {\n\t\t\t\treturn fn.(createAccumulator0x1[T0]).CreateAccumulator()\n\t\t\t})\n\t\t}\n\t}\n\tif m := accumVal.MethodByName(\"CreateAccumulator\"); m.IsValid() && createAccumulatorWrapper == nil {\n\t\tpanic(fmt.Sprintf(\"Failed to optimize CreateAccumulator for combiner %v. Failed to infer types\", accum))\n\t}\n\n\tvar addInputWrapper func(fn any) reflectx.Func\n\tif _, ok := accum.(addInput2x2[T0, T0]); ok {\n\t\tcaller := func(fn any) reflectx.Func {\n\t\t\tf := fn.(func(T0, T0) (T0, error))\n\t\t\treturn &caller2x2[T0, T0, T0, error]{fn: f}\n\t\t}\n\t\treflectx.RegisterFunc(reflect.TypeOf((*func(T0, T0) (T0, error))(nil)).Elem(), caller)\n\n\t\taddInputWrapper = func(fn any) reflectx.Func {\n\t\t\treturn reflectx.MakeFunc(func(a0 T0, a1 T0) (T0, error) {\n\t\t\t\treturn fn.(addInput2x2[T0, T0]).AddInput(a0, a1)\n\t\t\t})\n\t\t}\n\t} else if _, ok := accum.(addInput2x1[T0, T0]); ok {\n\t\tcaller := func(fn any) reflectx.Func {\n\t\t\tf := fn.(func(T0, T0) T0)","sourceCodeStart":7906,"sourceCodeEnd":7942,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/register/register.go#L7906-L7942","documentation":"This panic comes from Apache Beam Go's register.Combiner1 (or Combiner2) in register.go. When registering a CombineFn, the framework type-asserts the combiner against generic interfaces like createAccumulator0x1[T0]/createAccumulator0x2[T0] to build fast typed wrappers. If the combiner has a CreateAccumulator method (found via reflection) but it does not match either supported signature for the inferred type T0, no wrapper can be built and the library panics with this message rather than silently falling back to slow reflection.","triggerScenarios":"Calling register.Combiner1[T](&myCombiner{}) (or Combiner2) where myCombiner defines CreateAccumulator with a signature that is neither `CreateAccumulator() T` nor `CreateAccumulator() (T, error)` for the supplied type parameter T — e.g. it returns a different type than T0, takes arguments, or T was inferred/written incorrectly.","commonSituations":"Passing the wrong type parameter (Combiner2[AccumT, InputT] argument order swapped, or Combiner1[T] where the accumulator type differs from input type); a custom CombineFn whose CreateAccumulator returns a struct type different from the declared generic; upgrading Beam and migrating from reflection-based registration to the new typed Combiner registration API.","solutions":["Change CreateAccumulator to return exactly the accumulator type: `func (c *MyCombiner) CreateAccumulator() T` or `func (c *MyCombiner) CreateAccumulator() (T, error)`.","Ensure the type parameter passed to Combiner1[T0]/Combiner2[T0,T1] matches the actual accumulator return type (check Combiner2's [AccumT, OtherT] order).","If accumulator type differs from input/output type, switch from Combiner1 to Combiner2[T0, T1] with T0 = accumulator type.","Remove the CreateAccumulator method entirely if a zero value accumulator is acceptable (the wrapper is only mandatory for methods that exist)."],"exampleFix":"// before\nfunc (c *IntSum) CreateAccumulator() (int64, error) { return 0, nil }\nregister.Combiner1[int](&IntSum{})\n\n// after\nfunc (c *IntSum) CreateAccumulator() (int, error) { return 0, nil }\nregister.Combiner1[int](&IntSum{})","handlingStrategy":"validation","validationCode":"// Run at init time to fail fast:\nvar _ interface{ CreateAccumulator() int } = (*MyCombiner)(nil)\n// Or both supported shapes:\n// var _ interface{ CreateAccumulator() (int, error) } = (*MyCombiner)(nil)\nfunc validateCreateAccumulator[T0 any](c any) bool {\n\t_, e1 := c.(interface{ CreateAccumulator() T0 })\n\t_, e2 := c.(interface{ CreateAccumulator() (T0, error) })\n\treturn e1 || e2\n}","typeGuard":"func hasTypedCreateAccumulator[T0 any](c any) bool {\n\t_, ok1 := c.(interface{ CreateAccumulator() T0 })\n\t_, ok2 := c.(interface{ CreateAccumulator() (T0, error) })\n\treturn ok1 || ok2\n}","tryCatchPattern":null,"preventionTips":["Define methods with exactly the signatures documented on register.Combiner1/Combiner2.","Add compile-time interface assertions (var _ interface{...} = (*C)(nil)) next to the combiner definition.","Double-check the type parameter order: T0 is always the accumulator type.","Cover every register.CombinerN call in an init() or test so panics surface at startup, not mid-pipeline."],"tags":["go","apache-beam","combiner","type-inference","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-14T11:17:12.474Z"}