# V1013 worker_signature

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

> @worker marks a worker's entry, which a live worker starts by name with its two ports, so it sits on a non-generic function fn(Inbox<I>, Outbox<O>) -> Unit ! {Worker | e} (RFC 0002 §2.9).

An error from the `resolve` phase. `sakura explain V1013` prints this explanation offline.

`@worker` marks a worker's entry, which a live worker starts by name with its two ports, so
it sits on a non-generic function `fn(Inbox<I>, Outbox<O>) -> Unit ! {Worker | e}` (RFC 0002
§2.9). On a function of another shape, or on a type or constant, the entry could never be
spawned, so the attribute is rejected where it is written.

Wrong:

```sakura
@worker
fn double(n: Int) -> Int { n * 2 }
```

Fixed:

```sakura
@worker
fn double(inbox: Inbox<Int>, outbox: Outbox<Int>) -> Unit ! {Worker} { … }
```

## Wrong program [#wrong-program]

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

```sakura
// Spec: https://html.spec.whatwg.org/multipage/workers.html#dom-worker

// `@worker` marks an entry a live worker starts by name with its two ports, so it sits on a
// non-generic `fn(Inbox<I>, Outbox<O>) -> Unit`; on anything else the entry could never be
// spawned and the attribute is reported where it is written. `fine` and `pure` are accepted:
// an entry may perform fewer effects than `Worker`.
import std/worker.{Inbox, Outbox, Worker}

@worker
fn fine(_inbox: Inbox<Int>, _outbox: Outbox<Int>) -> Unit ! {Worker} {}

@worker
fn pure(_inbox: Inbox<Int>, _outbox: Outbox<Int>) -> Unit {}

@worker
fn double(n: Int) -> Int { n * 2 }

@worker
fn swapped(_outbox: Outbox<Int>, _inbox: Inbox<Int>) -> Unit ! {Worker} {}

@worker
fn answers(_inbox: Inbox<Int>, _outbox: Outbox<Int>) -> Int ! {Worker} { 1 }

@worker
fn generic<T>(_inbox: Inbox<T>, _outbox: Outbox<T>) -> Unit ! {Worker} {}

@worker
type Job = { id: Int }

pub fn main() -> Unit { let _ = Job { id: 1 } }
```

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

```json
{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:f0bed5a5af693094",
  "code": "V1013",
  "severity": "error",
  "phase": "resolve",
  "message": "`@worker` goes on a non-generic `fn(Inbox<I>, Outbox<O>) -> Unit`, any row: a worker is started by name with its two ports",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::V1013_worker_signature::double",
  "spans": [
    {
      "uri": "file://$DIR/V1013_worker_signature.sak",
      "content_hash": "sha256:d2f2e95a690cc71eba6aa54403bd1dd1d3e202d0c98ddfb473977779a9c41e61",
      "start_byte": 751,
      "end_byte": 757,
      "role": "primary"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V1013",
  "fixes": []
}
```

## Fixed program [#fixed-program]

No fixed program is checked in for this code yet; the explanation above describes the repair.
