Sakura Lang

V6010 non_std_effect_in_main

main's effect row may contain only std effects, because only they have host root handlers (design §9).

An error from the capability phase. sakura explain V6010 prints this explanation offline.

main's effect row may contain only std effects, because only they have host root handlers (design §9). Handle user effects inside main with with.

Wrong:

pub fn main() -> Unit ! {Db} { let _ = Db.count() }

Fixed:

pub fn main() -> Unit ! {Console} {
  with empty_db() { Console.print("{Db.count()} rows") }
}

Wrong program

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

effect Db {
  fn count() -> Int
}

pub fn main() -> Unit ! {Db} { let _ = Db.count() }

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

{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:5373cf157bc6101f",
  "code": "V6010",
  "severity": "error",
  "phase": "capability",
  "message": "only std effects may appear in `main`'s row, because only they have host handlers; handle `Db` (from `main/V6010_non_std_effect_in_main`) inside `main` with `with` and remove it from the row",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::V6010_non_std_effect_in_main::main",
  "spans": [
    {
      "uri": "file://$DIR/V6010_non_std_effect_in_main.sakura",
      "content_hash": "sha256:078c14d559d336cea5c09610d1a85ad083cbda818318ac750afcd2aceb5d8c23",
      "start_byte": 94,
      "end_byte": 96,
      "role": "primary"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V6010",
  "fixes": []
}

Fixed program

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

effect Db {
  fn count() -> Int
}

fn empty_db() -> Handler<Db> {
  handler Db {
    fn count() { 0 }
  }
}

pub fn main() -> Unit ! {Console} { with empty_db() { Console.print("{Db.count()} rows") } }
Edit on GitHub

On this page