apache/beam · error
Mismatched restriction type in method %v, parameter at index
Error message
Mismatched restriction type in method %v, parameter at index %v. Got: %v, Want: %v (from method %v). Ensure that all restrictions in an SDF are the same type.
What it means
In SplitRestriction, the restriction parameter's type must exactly equal the restriction type produced by CreateInitialRestriction. This error (raised from validateSdfSignatures for splitRestrictionName) fires when reflect type identity fails between the SplitRestriction param at the restriction position and the restriction type from CreateInitialRestriction.
Source
Thrown at sdks/go/pkg/beam/core/graph/fn.go:1015
restrictionT := fn.methods[createInitialRestrictionName].Ret[0].T
rTrackerT := reflect.TypeOf((*sdf.RTracker)(nil)).Elem()
for _, name := range requiredSdfNames {
method := fn.methods[name]
startIdx := sdfRequiredParamStartIndex(method)
switch name {
case createInitialRestrictionName:
if err := validateSdfElementT(fn, createInitialRestrictionName, method, num, startIdx); err != nil {
return err
}
case splitRestrictionName:
if err := validateSdfElementT(fn, splitRestrictionName, method, num, startIdx); err != nil {
return err
}
idx := num + startIdx
if method.Param[idx].T != restrictionT {
err := errors.Errorf("mismatched restriction type in method %v, param %v. got: %v, want: %v",
splitRestrictionName, idx, method.Param[idx].T, restrictionT)
return errors.SetTopLevelMsgf(err, "Mismatched restriction type in method %v, "+
"parameter at index %v. Got: %v, Want: %v (from method %v). "+
"Ensure that all restrictions in an SDF are the same type.",
splitRestrictionName, idx, method.Param[idx].T, restrictionT, createInitialRestrictionName)
}
if method.Ret[0].T.Kind() != reflect.Slice ||
method.Ret[0].T.Elem() != restrictionT {
err := errors.Errorf("invalid output type in method %v, return %v. got: %v, want: %v",
splitRestrictionName, 0, method.Ret[0].T, reflect.SliceOf(restrictionT))
return errors.SetTopLevelMsgf(err, "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.",
splitRestrictionName, 0, method.Ret[0].T, reflect.SliceOf(restrictionT), createInitialRestrictionName, splitRestrictionName)
}
case restrictionSizeName:
if err := validateSdfElementT(fn, restrictionSizeName, method, num, startIdx); err != nil {
return errView on GitHub (pinned to 12126d8942)
Solutions
- Make SplitRestriction's restriction parameter exactly the same concrete type returned by CreateInitialRestriction.
- Remove any interface or wrapper type around the restriction parameter; use the concrete restriction struct.
- Unify duplicate restriction type definitions into one shared type.
- Check for named-type vs underlying-type mismatches (reflection requires exact type identity).
Example fix
// before
func (fn *myFn) SplitRestriction(r otherRestriction) (truncIntRange, error) { ... }
// after
func (fn *myFn) SplitRestriction(r truncIntRange) ([]truncIntRange, error) { ... } Defensive patterns
Strategy: validation
Validate before calling
// Assert restriction type identity across SDF methods:
func checkRestrictionTypes(t reflect.Type) error {
cir, _ := t.MethodByName("CreateInitialRestriction")
sr, _ := t.MethodByName("SplitRestriction")
want := cir.Type.Out(0)
// SplitRestriction: receiver + optional ctx + element(s) + restriction
got := sr.Type.In(sr.Type.NumIn() - 1)
if got != want {
return fmt.Errorf("SplitRestriction restriction %v != CreateInitialRestriction %v", got, want)
}
return nil
} Prevention
- Define the restriction type once and reference it in every SDF method
- Avoid interfaces/pointers around restriction types
- Grep all SDF methods for the restriction type name after refactors
When it happens
Trigger: SplitRestriction accepting a differently named/typed restriction struct or an interface instead of the concrete restriction type returned by CreateInitialRestriction.
Common situations: Defining two similar restriction types (e.g. rangeTracker vs offsetRange) across files; using a generic or alias type; copying an SDF and renaming the restriction only in some methods.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Invalid output type in method %v, return value at index %v.
- Mismatched output type in method %v, return value at index %
- invalid number of main input params in method %v. got: %v, w
- unexpected number of params in method %v. got: %v, want: %v
- unexpected number of returns in method %v. got: %v, want: %v
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/48b5153058825e20.
Report an issue: GitHub.