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.sakura, 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:61ad7e6f1b4ce063",
  "code": "V2002",
  "severity": "error",
  "phase": "type",
  "message": "this call passes 2 arguments to a function of type `fn(Int) -> Int`, which takes 1",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::V2002_arity_mismatch::four",
  "spans": [
    {
      "uri": "file://$DIR/V2002_arity_mismatch.sakura",
      "content_hash": "sha256:c871525ab5c724ef81dd0f38e0dad00386ca60537d36d8e833a2e8bfe7e61031",
      "start_byte": 89,
      "end_byte": 101,
      "role": "primary"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V2002",
  "fixes": []
}

More fixtures for this code: compiler/tests/ui/V2002_row_argument_count.sakura.

Fixed program

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

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

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

On this page