Diagnostics#
Use ms check while editing to find mistakes before running the program. A diagnostic tells you where the problem is, what rule failed and how to repair it.
Follow a repair#
Save this program as count.ms:
fn main() Void {
var count = 2
count += 1
print(count)
}ms run count.ms3Change var count to count := ..., then run ms check count.ms. It exits with status 1 and points to the assignment on line 3. The diagnostic message is:
cannot assign immutable binding count; declare it with 'var count = ...' instead of 'count := ...'Here the intended repair is mechanical, so you can apply it and run again:
ms check --only types count.ms --fix
ms run count.msThe checker reports ms: applied 1 fix in 1 file and Checked count.ms; the program prints 3 again. Review applied edits before keeping them. When a repair needs a choice about the program’s meaning, follow the explanation and edit the source yourself.
Each diagnostic also has a stable rule code and source position for editor and agent integrations. The same error is MS3060 in ms check --only types count.ms --json; the JSON includes the exact replacement range and "replacement": "var".
Message shape#
Messages read <cause>; <fix>. The cause uses stable wording and names the offending name, type, or count.
The fix says what to write, such as did you mean 'count'?, add: import panic from "@std/core.ms", declare it with 'var count = ...' instead of 'count := ...', or the valid arguments, members, cases, or exports. Codes classify only the text before the first ; , and follow-on errors that restate an earlier one are not reported.
Explaining a violated rule#
A diagnostic names the violated rule and the declaration or call site involved. Runtime closed-resource faults carry the operation and the source location as separate fields.
JSON diagnostics#
ms check --only types file.ms --json emits {"format": 1, "diagnostics": [...]}. Each diagnostic has code, phase, message, and position with file, one-based line/UTF-8 byte column, and original-byte offset. Empty results use []. CRLF normalization preserves original offsets. --with-text adds text with the stdout and stderr the command prints without --json, so one run yields both. With several inputs, --each reports each as its own result, {"results": [{"target", "exit_code", "document"}]}, from one standard-library load.
Several inputs share one document; see analysis selection
.
Each diagnostic’s position, end, and fix boundaries use the same source-path spelling, including paths relative to the invocation directory for collection inputs.
Optional
endhas the same coordinate fields (exclusive). Parser token errors and failed import names provide it.An optional
fixhasposition, an exclusiveend, andreplacement: replace that byte range in the original snapshot, then recheck. These diagnostics carry one:- redundant prelude imports, and misspelled names, members, labels and types with one
did you meancandidate - unresolved standard names and the
Decimalliteral import (animportinserted at the top of the file) Some/Ok/Err/True/null/thishabits, andCase()on a nullary case- assignment to a
:=binding (:=becomesvar) - an
Intused asFloat(.to_float(), or3.0for a literal), and anInt,FloatorBoolused asString(f"{value}") ms check --only lintunused imports (MSL102: the name with its separator, or the whole statement)
String-match rewrites, ambiguous imports and ownership errors get prose only: a machine-applied
.clone()would hide the design choice and cost time and memory.ms check --only types --fixandms check --only lint --fixapply these edits in place (skipping overlaps), then report what remains.- redundant prelude imports, and misspelled names, members, labels and types with one
Optional
subcode(MS3000.1) names the cause within the familycode; it is absent for messages without a known cause. Sub-codes are never renumbered or reused.Consumers must tolerate absent optional fields.
| Code | Family |
|---|---|
| MS1000, MS1001, MS1002 | Grammar, literals/text, layout |
| MS2001, MS2002, MS2003 | Names/members, modules, redundant canonical prelude imports |
| MS3000, MS3001 | General typing, exact types/operators |
| MS3002-3004 | Duplicate, missing, unknown arguments |
| MS3010, MS3012 | Implementations |
| MS3021 | Hashing |
| MS3030, MS3040, MS3050, MS3060 | Captures, recursion, exhaustiveness, mutation |
| MS3070, MS3080 | Numeric literals, generic inference |
| MS4000 | Lowering |
ms help <code> prints a code’s or sub-code’s family and usual repair (--json for structured output), for example ms help MS3000.1.
For the language rules behind a diagnostic, start with variables and values and references .