{"record":{"id":"7872e1600c1fcb09","repo":"apache/beam","slug":"invalid-output-type-in-method-v-return-value-at-index-v-got","errorCode":null,"errorMessage":"Invalid output type in method %v, return value at index %v. Got: %v, Want: %v (from method %v). Ensure that all restrictions in an SDF are the same type, and that %v returns a slice.","messagePattern":"Invalid output type in method (.+?), return value at index (.+?)\\. Got: (.+?), Want: (.+?) \\(from method (.+?)\\)\\. Ensure that all restrictions in an SDF are the same type, and that (.+?) returns a slice\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/fn.go","lineNumber":1024,"sourceCode":"\t\t\tif err := validateSdfElementT(fn, createInitialRestrictionName, method, num, startIdx); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\tcase splitRestrictionName:\n\t\t\tif err := validateSdfElementT(fn, splitRestrictionName, method, num, startIdx); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tidx := num + startIdx\n\t\t\tif method.Param[idx].T != restrictionT {\n\t\t\t\terr := errors.Errorf(\"mismatched restriction type in method %v, param %v. got: %v, want: %v\",\n\t\t\t\t\tsplitRestrictionName, idx, method.Param[idx].T, restrictionT)\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\tsplitRestrictionName, idx, method.Param[idx].T, restrictionT, createInitialRestrictionName)\n\t\t\t}\n\t\t\tif method.Ret[0].T.Kind() != reflect.Slice ||\n\t\t\t\tmethod.Ret[0].T.Elem() != restrictionT {\n\t\t\t\terr := errors.Errorf(\"invalid output type in method %v, return %v. got: %v, want: %v\",\n\t\t\t\t\tsplitRestrictionName, 0, method.Ret[0].T, reflect.SliceOf(restrictionT))\n\t\t\t\treturn errors.SetTopLevelMsgf(err, \"Invalid 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 restrictions in an SDF are the same type, and that %v returns a slice.\",\n\t\t\t\t\tsplitRestrictionName, 0, method.Ret[0].T, reflect.SliceOf(restrictionT), createInitialRestrictionName, splitRestrictionName)\n\t\t\t}\n\t\tcase restrictionSizeName:\n\t\t\tif err := validateSdfElementT(fn, restrictionSizeName, method, num, startIdx); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tidx := num + startIdx\n\t\t\tif method.Param[idx].T != restrictionT {\n\t\t\t\terr := errors.Errorf(\"mismatched restriction type in method %v, param %v. got: %v, want: %v\",\n\t\t\t\t\trestrictionSizeName, idx, method.Param[idx].T, restrictionT)\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\trestrictionSizeName, idx, method.Param[idx].T, restrictionT, createInitialRestrictionName)","sourceCodeStart":1006,"sourceCodeEnd":1042,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/fn.go#L1006-L1042","documentation":"SplitRestriction must return a slice whose element type is exactly the restriction type from CreateInitialRestriction. This error fires when the first return value is not a slice of that restriction type (wrong element type, not a slice, or a pointer type).","triggerScenarios":"SplitRestriction returning []OtherRestriction, a single restriction value, []*T instead of []T, or a non-slice collection.","commonSituations":"Returning a pointer-to-restriction slice because the restriction type was changed to pointer form in some methods; returning one restriction without wrapping it in a slice; changing the restriction type in CreateInitialRestriction without updating the slice element type.","solutions":["Return a slice of the exact restriction type: []RestrictionType from CreateInitialRestriction.","Remove pointer indirection if the restriction is a value type ([]T not []*T).","Ensure the slice element type matches the restriction type identically (exact reflect equality).","If returning an error, keep the slice first and error last."],"exampleFix":"// before\nfunc (fn *myFn) SplitRestriction(r myRestriction) ([]*myRestriction, error) { ... }\n\n// after\nfunc (fn *myFn) SplitRestriction(r myRestriction) ([]myRestriction, error) { ... }","handlingStrategy":"validation","validationCode":"// Assert SplitRestriction returns []RestrictionType:\nfunc checkSplitReturn(t reflect.Type) error {\n    cir, _ := t.MethodByName(\"CreateInitialRestriction\")\n    sr, _ := t.MethodByName(\"SplitRestriction\")\n    want := reflect.SliceOf(cir.Type.Out(0))\n    got := sr.Type.Out(0)\n    if got != want {\n        return fmt.Errorf(\"SplitRestriction return %v, want %v\", got, want)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always return a value slice ([]T), not pointers ([]*T)","Update SplitRestriction's slice element type whenever the restriction type changes","Add compile-time reflection checks in package tests"],"tags":["go","apache-beam","sdf","type-mismatch","reflection"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}