# V2004 unknown_field

URL: /docs/errors/V2004
Markdown: /docs/errors/V2004.md

> The record type has no field with this name, or a record literal is missing required fields or names an extra one.

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

The record type has no field with this name, or a record literal is missing required fields or
names an extra one. Check the type's declaration for the field names; a record literal must list
every field (or start from another value with `{ ..r, field: v }`).

Wrong:

```sakura
type Point = { x: Int, y: Int }
fn depth(p: Point) -> Int { p.z }
```

Fixed:

```sakura
fn depth(p: Point) -> Int { p.y }
```

## Wrong program [#wrong-program]

[`compiler/tests/ui/V2004_unknown_field.sakura`](https://github.com/icantcodefyi/sakuralang/blob/master/compiler/tests/ui/V2004_unknown_field.sakura), which the compiler's ui suite runs through `sakura check`:

```sakura
type Point = { x: Int, y: Int }

fn depth(p: Point) -> Int { p.z }
```

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

```json
{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:049e5bc6e6c7ffa8",
  "code": "V2004",
  "severity": "error",
  "phase": "type",
  "message": "`Point` has no field `z`; its fields are `x`, `y`",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::V2004_unknown_field::depth",
  "spans": [
    {
      "uri": "file://$DIR/V2004_unknown_field.sakura",
      "content_hash": "sha256:26b824edfe6805bb39737d8cbc2a61fa872417ca248585185ad9f0858d8ec9a6",
      "start_byte": 95,
      "end_byte": 98,
      "role": "primary"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V2004",
  "fixes": []
}
```

## Fixed program [#fixed-program]

[`compiler/tests/ui/V2004_unknown_field.fixed.sakura`](https://github.com/icantcodefyi/sakuralang/blob/master/compiler/tests/ui/V2004_unknown_field.fixed.sakura), which `sakura check` accepts with no diagnostics:

```sakura
type Point = { x: Int, y: Int }

fn depth(p: Point) -> Int { p.y }
```
