{"record":{"id":"6b5d633ee456e20f","repo":"apache/beam","slug":"mismatched-output-type-in-method-v-return-value-at-index-v-6b5d63","errorCode":null,"errorMessage":"mismatched output type in method %v, return value at index %v got: %v, want: %v (from method %v). Ensure that all watermark states in an SDF are the same type.","messagePattern":"mismatched output type in method (.+?), return value at index (.+?) got: (.+?), want: (.+?) \\(from method (.+?)\\)\\. Ensure that all watermark states in an SDF are the same type\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/fn.go","lineNumber":1303,"sourceCode":"\t\t\t\t\tinitialWatermarkEstimatorStateName, 1, method.Param[1].T, restT)\n\t\t\t\treturn errors.SetTopLevelMsgf(err, \"mismatched restriction type in method %v, \"+\n\t\t\t\t\t\"parameter at index %v. got: %v, want: %v (from method %v). \"+\n\t\t\t\t\t\"Ensure that all restrictions in an SDF are the same type.\",\n\t\t\t\t\tinitialWatermarkEstimatorStateName, 1, method.Param[1].T, restT, createTrackerName)\n\t\t\t}\n\t\t\tif err := validateSdfElementT(fn, initialWatermarkEstimatorStateName, method, numMainIn, 2); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tif len(method.Ret) != 1 {\n\t\t\t\terr := errors.Errorf(\"unexpected number of elements returned in method %v. got: %v, want %v\",\n\t\t\t\t\tinitialWatermarkEstimatorStateName, len(method.Ret), 1)\n\t\t\t\treturn errors.SetTopLevelMsgf(err, \"unexpected number of elements returned in method %v. \"+\n\t\t\t\t\t\"got: %v, want %v. Check that the signature conforms to the expected signature for %v.\",\n\t\t\t\t\tinitialWatermarkEstimatorStateName, len(method.Ret), 1, initialWatermarkEstimatorStateName)\n\t\t\t}\n\t\t\tif method.Ret[0].T != watermarkStateT {\n\t\t\t\terr := errors.Errorf(\"mismatched output type in method %v, return %v. got: %v, want: %v\",\n\t\t\t\t\tcreateWatermarkEstimatorName, 0, method.Ret[0].T, watermarkStateT)\n\t\t\t\treturn errors.SetTopLevelMsgf(err, \"mismatched output type in method %v, \"+\n\t\t\t\t\t\"return value at index %v got: %v, want: %v (from method %v). \"+\n\t\t\t\t\t\"Ensure that all watermark states in an SDF are the same type.\",\n\t\t\t\t\tcreateWatermarkEstimatorName, 0, method.Ret[0].T, watermarkStateT, createWatermarkEstimatorName)\n\t\t\t}\n\t\tcase watermarkEstimatorStateName:\n\t\t\tif len(method.Param) != 1 {\n\t\t\t\terr := errors.Errorf(\"unexpected number of params in method %v. got: %v, want %v\",\n\t\t\t\t\twatermarkEstimatorStateName, len(method.Param), 1)\n\t\t\t\treturn errors.SetTopLevelMsgf(err, \"unexpected number of parameters in method %v. \"+\n\t\t\t\t\t\"got: %v, want %v. Check that the signature conforms to the expected signature for %v, \"+\n\t\t\t\t\t\"and that elements in SDF method parameters match elements in %v.\",\n\t\t\t\t\twatermarkEstimatorStateName, len(method.Param), 1, watermarkEstimatorStateName, processElementName)\n\t\t\t}\n\t\t\tif method.Param[0].T != watermarkEstimatorT {\n\t\t\t\terr := errors.Errorf(\"mismatched watermark state type in method %v, return %v. got: %v, want: %v\",\n\t\t\t\t\twatermarkEstimatorStateName, 0, method.Param[0].T, watermarkEstimatorT)","sourceCodeStart":1285,"sourceCodeEnd":1321,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/fn.go#L1285-L1321","documentation":"Within one stateful SDF, the watermark state type must be identical across methods. Beam validates that WatermarkEstimatorState's return type exactly equals the state type returned by CreateWatermarkEstimator; if they differ, validation fails with this error naming CreateWatermarkEstimator as the source of the expected type.","triggerScenarios":"WatermarkEstimatorState returns a different type than CreateWatermarkEstimator's return value — e.g. returning the state struct while CreateWatermarkEstimator returns an estimator wrapper, or a value vs pointer mismatch.","commonSituations":"Refactoring the state type in one method only; introducing a wrapper estimator type and updating only one signature; aliases or generics making types look identical but resolve differently.","solutions":["Make WatermarkEstimatorState return exactly the same type CreateWatermarkEstimator returns.","If one method returns *myState and the other myState, unify on one form.","Extract the state from the estimator consistently (e.g. a shared accessor returning the common type).","Grep all watermark-state-related signatures in the DoFn and verify a single state type is used everywhere."],"exampleFix":"// before\nfunc (f *fn) CreateWatermarkEstimator(rest MyRestriction) *myEstimator { return &myEstimator{} }\nfunc (f *fn) WatermarkEstimatorState(we sdf.WatermarkEstimator) myEstimator { ... }\n// after\nfunc (f *fn) CreateWatermarkEstimator(rest MyRestriction) *myEstimator { return &myEstimator{} }\nfunc (f *fn) WatermarkEstimatorState(we sdf.WatermarkEstimator) *myEstimator {\n    return we.(*myEstimator)\n}","handlingStrategy":"validation","validationCode":"var cwRet myEstimator = (*fn)(nil).CreateWatermarkEstimator(MyRestriction{}) // type must match WatermarkEstimatorState return\nvar _ func(sdf.WatermarkEstimator) myEstimator = (*fn).WatermarkEstimatorState","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a single named state type for both CreateWatermarkEstimator's return and WatermarkEstimatorState's return.","Unify value vs pointer usage across the two signatures.","Change the state type in both methods in the same edit."],"tags":["go","apache-beam","sdf","watermark-estimator","type-mismatch"],"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"}