verify method

void verify(
  1. int positional,
  2. Set<String> names
)

Throws a SassScriptException if positional and names aren't valid for this argument declaration.

Implementation

void verify(int positional, Set<String> names) {
  var namedUsed = 0;
  for (var i = 0; i < arguments.length; i++) {
    var argument = arguments[i];
    if (i < positional) {
      if (names.contains(argument.name)) {
        throw SassScriptException(
            "Argument ${_originalArgumentName(argument.name)} was passed "
            "both by position and by name.");
      }
    } else if (names.contains(argument.name)) {
      namedUsed++;
    } else if (argument.defaultValue == null) {
      throw MultiSpanSassScriptException(
          "Missing argument ${_originalArgumentName(argument.name)}.",
          "invocation",
          {spanWithName: "declaration"});
    }
  }

  if (restArgument != null) return;

  if (positional > arguments.length) {
    throw MultiSpanSassScriptException(
        "Only ${arguments.length} "
            "${names.isEmpty ? '' : 'positional '}"
            "${pluralize('argument', arguments.length)} allowed, but "
            "$positional ${pluralize('was', positional, plural: 'were')} "
            "passed.",
        "invocation",
        {spanWithName: "declaration"});
  }

  if (namedUsed < names.length) {
    var unknownNames = Set.of(names)
      ..removeAll(arguments.map((argument) => argument.name));
    throw MultiSpanSassScriptException(
        "No ${pluralize('argument', unknownNames.length)} named "
            "${toSentence(unknownNames.map((name) => "\$$name"), 'or')}.",
        "invocation",
        {spanWithName: "declaration"});
  }
}