Sakura Lang

V2002 arity_mismatch

A function was called with the wrong number of arguments, or a pattern has the wrong number of fields.

An error from the type phase. sakura explain V2002 prints this explanation offline.

A function was called with the wrong number of arguments, or a pattern has the wrong number of fields. The diagnostic's expected and actual carry both counts; arguments are positional, with no defaults (pass a record when a call needs options).

Wrong:

fn double(x: Int) -> Int { x * 2 }
fn four() -> Int { double(2, 2) }

Fixed:

fn four() -> Int { double(2) }

Wrong program

compiler/tests/ui/V2002_arity_mismatch.sak, which the compiler's ui suite runs through sakura check:

fn double(x: Int) -> Int { x * 2 }

fn four() -> Int { double(2, 2) }

sakura check --json reports this record (pretty-printed; $DIR is the fixture's directory):

{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:5f6e42c350a5bf1f",
  "code": "V2002",
  "severity": "error",
  "phase": "type",
  "message": "`double` (main/V2002_arity_mismatch) takes 1 argument, this call passes 2",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::V2002_arity_mismatch::four",
  "spans": [
    {
      "uri": "file://$DIR/V2002_arity_mismatch.sak",
      "content_hash": "sha256:c871525ab5c724ef81dd0f38e0dad00386ca60537d36d8e833a2e8bfe7e61031",
      "start_byte": 89,
      "end_byte": 101,
      "role": "primary"
    }
  ],
  "related_ids": [],
  "expected": {
    "render": "1"
  },
  "actual": {
    "render": "2"
  },
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V2002",
  "fixes": []
}

More fixtures for this code: compiler/tests/ui/V2002_function_value_keeps_type.sak, compiler/tests/ui/V2002_names_callee_and_module.sak, compiler/tests/ui/V2002_row_argument_count.sak.

Fixed program

compiler/tests/ui/V2002_arity_mismatch.fixed.sak, which sakura check accepts with no diagnostics:

fn double(x: Int) -> Int { x * 2 }

fn four() -> Int { double(2) }
Edit on GitHub

Last updated

On this page