{"record":{"id":"7c4e233c13e3621f","repo":"apache/beam","slug":"mismatched-element-type-in-method-v-parameter-at-index-v-got","errorCode":null,"errorMessage":"Mismatched element type in method %v, parameter at index %v. Got: %v, Want: %v (from method %v). Ensure that element parameters in SDF methods have consistent types with element parameters in %v.","messagePattern":"Mismatched element type in method (.+?), parameter at index (.+?)\\. Got: (.+?), Want: (.+?) \\(from method (.+?)\\)\\. Ensure that element parameters in SDF methods have consistent types with element parameters in (.+?)\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/fn.go","lineNumber":1141,"sourceCode":"\t\treturn ctxIndex + 1\n\t}\n\n\treturn 0\n}\n\n// validateSdfElementT validates that element types in an SDF method are\n// consistent with the ProcessElement method. This method assumes that the\n// first 'num' parameters starting with startIndex are the elements.\nfunc validateSdfElementT(fn *Fn, name string, method *funcx.Fn, num int, startIndex int) error {\n\t// ProcessElement is the most canonical source of the element type. We can\n\t// processFn is valid by this point and skip unnecessary validation.\n\tprocessFn := fn.methods[processElementName]\n\tpos, _, _ := processFn.Inputs()\n\n\tfor i := 0; i < num; i++ {\n\t\tidx := i + startIndex\n\t\tif got, want := method.Param[i+startIndex].T, processFn.Param[pos+i].T; got != want {\n\t\t\terr := errors.Errorf(\"mismatched element type in method %v, param %v. got: %v, want: %v\",\n\t\t\t\tname, idx, got, want)\n\t\t\treturn errors.SetTopLevelMsgf(err, \"Mismatched element type in method %v, \"+\n\t\t\t\t\"parameter at index %v. Got: %v, Want: %v (from method %v). \"+\n\t\t\t\t\"Ensure that element parameters in SDF methods have consistent types with element parameters in %v.\",\n\t\t\t\tname, idx, got, want, processElementName, processElementName)\n\t\t}\n\t}\n\treturn nil\n}\n\n// validateIsWatermarkEstimating returns true if watermark estimator methods are present on the DoFn, returns\n// false if they aren't, and returns an error if they are present but the function isn't an sdf and thus doesn't\n// support watermark estimation\nfunc validateIsWatermarkEstimating(fn *Fn, isSdf bool) (bool, error) {\n\t_, isWatermarkEstimating := fn.methods[createWatermarkEstimatorName]\n\tif !isSdf && isWatermarkEstimating {\n\t\treturn false, errors.Errorf(\"watermark estimation method %v is defined on non-splittable DoFn. Watermark\"+\n\t\t\t\"estimation is only valid on splittable DoFns\", createWatermarkEstimatorName)","sourceCodeStart":1123,"sourceCodeEnd":1159,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/fn.go#L1123-L1159","documentation":"Element parameters of SDF methods (SplitRestriction, TruncateRestriction, ProcessElement, Size, etc.) must use consistent types across all methods. Beam compares each parameter's type against the corresponding element parameter of ProcessElement and fails when they differ.","triggerScenarios":"Defining e.g. Size(r MyRestriction) or SplitRestriction(r OtherRestriction) while ProcessElement takes a different element/restriction type; mismatch at parameter index idx = i + startIndex for method 'name'.","commonSituations":"Refactoring the element type in ProcessElement but not in auxiliary methods; using generic type parameters inconsistently across methods; copying method signatures from another DoFn.","solutions":["Align the element/restriction parameter types of the failing method with ProcessElement's corresponding parameter (the message gives Got/Want types and the index).","Update all SDF methods together whenever the element type changes.","If using Go generics, instantiate all methods with the same type parameters."],"exampleFix":"// before\nfunc (fn *f) ProcessElement(ctx, r RestA, elem string, emit func(int)) {...}\nfunc (fn *f) Size(r RestB) int {...}\n// after\nfunc (fn *f) Size(r RestA) int {...}","handlingStrategy":"validation","validationCode":"func validateElementTypes(fn interface{}) error {\n    // Beam validates at graph construction; pre-check in tests:\n    if _, err := beam.TryCreateDoFn(reflect.TypeOf(fn)); err != nil {\n        return err\n    }\n    return nil\n}","typeGuard":"func elementTypesMatch(fn interface{}) bool {\n    t := reflect.TypeOf(fn)\n    pe, a := t.MethodByName(\"ProcessElement\")\n    sz, b := t.MethodByName(\"Size\")\n    return !a || !b || pe.Type.In(pe.Type.NumIn()-1) != sz.Type.In(1) // adjust for actual param layout\n}","tryCatchPattern":null,"preventionTips":["Change element/restriction types in all SDF methods atomically.","Run `go test` on the transform package; add a beam.TryCreateDoFn smoke test."],"tags":["go","apache-beam","splittable-dofn","validation"],"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"}