Sakura Lang

V0015 source_not_utf8

The source file is not UTF-8.

An error from the lex phase. sakura explain V0015 prints this explanation offline.

The source file is not UTF-8. Sakura Lang source is UTF-8 text; the message names the first invalid byte and its offset, where the span points. The rest of that file is not checked until its encoding is fixed (its other diagnostics would be about text it does not hold); the other files are checked as usual. Save the file as UTF-8: a Latin-1 é is the byte 0xE9, which UTF-8 writes as 0xC3 0xA9. sakura fmt and edits leave such a file untouched.

Wrong program

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

app.sak:

// A source file that is not UTF-8 is `V0015` at its first invalid byte, and nothing else in it
// is reported; the other files are checked (design §17.243 (3), §17.253 (1)). `names.sak` holds
// one Latin-1 byte, 0xE9, in a string, and a type error after it.
import main/names

pub fn shout() -> String { names.greeting() }

pub fn wrong() -> Int { "not an Int" }

names.sak:

// This file is not UTF-8 (byte 0xE9 at offset 34), so it is not shown here.

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

{
  "schema_version": "1.0",
  "kind": "diagnostic",
  "id": "d:2793314a34d79255",
  "code": "V0015",
  "severity": "error",
  "phase": "lex",
  "message": "the source file is not UTF-8: invalid byte 0xE9 at offset 34",
  "snapshot": "sha256:$SNAPSHOT",
  "symbol_id": "main::names::greeting",
  "spans": [
    {
      "uri": "file://$DIR/V0015_source_not_utf8/names.sak",
      "content_hash": "sha256:d0ce10fec2fa3c2e152f736c307617b796c1762ee76f8a46f6586f5df9af23ad",
      "start_byte": 34,
      "end_byte": 34,
      "role": "primary"
    }
  ],
  "related_ids": [],
  "expected": null,
  "actual": null,
  "obligation": null,
  "counterexample": null,
  "explanation_uri": "sakura://explain/V0015",
  "fixes": []
}

Fixed program

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

Edit on GitHub

Last updated

On this page