getRequiredArg<T> static method

T getRequiredArg<T>(
  1. List<Object?> positional,
  2. int index,
  3. String paramName,
  4. String methodName,
)

Get a required positional argument, bounds-checked and type-extracted.

This is the GENERATED-code entry point. tom_d4rt_generator emits it; the hand-written stdlib under lib/src/stdlib/ does not use it, and checkArity is what that side reaches for instead. stdlib_d4_boundary_test pins the split so it stays a stated boundary rather than an accident.

The two sides differ in what they throw, and the difference is real rather than cosmetic:

  • this pair throws ArgumentD4rtException — generated bridges and their tests depend on it, which is why SCC87 chose not to change it;
  • checkArity throws RuntimeD4rtException, matching what the stdlib dispatch path already produced and what describeArityError emits, so a hand-written bridge reports arity failures the same way whether the guard is explicit or generic.

Both are siblings under D4rtException, so a script that wants every bridge argument failure catches THAT and gets all of them. What it cannot do is pick one subtype and be sure it has covered the surface — worth knowing before writing on ArgumentD4rtException in a script.

Throws ArgumentD4rtException when the argument is missing or has the wrong type. (The previous wording here said ArgumentError, which is a different class this method never throws.)

Implementation

static T getRequiredArg<T>(
  List<Object?> positional,
  int index,
  String paramName,
  String methodName,
) {
  if (positional.length <= index) {
    throw ArgumentD4rtException(
      '$methodName: Missing required argument "$paramName" at position $index. '
      'Expected at least ${index + 1} arguments, got ${positional.length}',
    );
  }
  return extractBridgedArg<T>(positional[index], paramName);
}