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 err

View on GitHub (pinned to 12126d8942)

Solutions

  1. Make SplitRestriction's restriction parameter exactly the same concrete type returned by CreateInitialRestriction.
  2. Remove any interface or wrapper type around the restriction parameter; use the concrete restriction struct.
  3. Unify duplicate restriction type definitions into one shared type.
  4. 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

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


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/48b5153058825e20. Report an issue: GitHub.