VOID Diagnostics

Show the source.
Explain the rule.

One compiler-owned diagnostic model carries severity, stable codes, messages, source spans, notes, help, and related locations. Terminal and JSON output are two presentations of the same compiler information.

Structured diagnostics

An error can point at the failure and explain the contract around it.

Diagnostics retain half-open UTF-8 source spans and compiler-owned source snapshots, so terminal rendering can show the exact loaded source with insertion points, multiline excerpts, tabs, UTF-8 text, and related locations without rereading a file that may have changed.

One structured model

Lexer, parser, semantic, generic-specialization, and driver failures route through compiler-owned diagnostic records instead of separate terminal-only error paths.

Source excerpts & spans

Primary and related locations render from compiler snapshots with precise markers, including zero-width insertions, multiline spans, tabs, UTF-8 source, CRLF, and final lines without trailing newlines.

Notes & related context

Diagnostics can point to declarations, parameters, interface or base contracts, generic declarations, overload candidates, and other locations that explain why the primary source is invalid.

Confident help

Known missing quotes or delimiters, static-class misuse, and mutation of in parameters can receive first-class help. Unknown names do not get speculative spelling guesses.

Parser recovery

Common syntax failures keep one useful root diagnostic and recover conservatively at top-level boundaries so later syntax can still be inspected without accepting the invalid program.

Stable VOIDxxxx codes

Public diagnostic families have centralized stable identifiers for lexical, syntax, semantic, and driver/project/build failures. Existing broad fallback families remain intentional where a narrower code is not yet defined.

Machine-readable diagnostics

--diagnostics=json emits schema-versioned JSON records with the same code, severity, message, spans, notes, help, related locations, and truncation state used by human-readable output.

Human and machine output

One diagnostic record. Multiple presentations.

Terminal text and JSON are rendered from the same compiler information, so tooling does not need to scrape human-readable stderr to recover codes or source locations. Redirected terminal output remains readable without depending on ANSI color, while JSON safely escapes control bytes, Unicode, unusual paths, and multiline text.

Compiler to editor

Existing LSP diagnostics still come from the compiler.

voidc lsp continues to publish lexer, parser, and semantic diagnostics from synchronized in-memory source and uses the same compiler semantics as real builds. Full transport of every new rich note/help/related-location context through LSP is still a separate future step, as are code actions and automatic fixes.

Current terminal diagnostic
./Program.void:8:20-8:38: error: cannot assign 'string' to local 'name' of type 'int'
       code: VOID3002
     8 |         int name = Console.ReadLine();
       |                    ^~~~~~~~~~~~~~~~~~
./Program.void:8:9-8:12: note: Target local type is declared here.
     8 |         int name = Console.ReadLine();
       |         ^~~
note: Local initialization requires an implicit conversion; explicit conversions are not applied automatically.

VOID3002 is a stable semantic diagnostic-family identifier for incompatible value conversion. Stable codes name diagnostic families; they do not imply that every individual message wording receives a unique code.

Runtime diagnostics

The immediate failure stays visible before the stack.

Runtime failures now use the same developer-first idea as compiler diagnostics: show the relevant VOID source excerpt and span first, then the complete synchronous VOID call stack. Throw, rethrow, nested handlers, constructors, properties, lambdas, static initialization, generics, and internal runtime failures preserve known source origins and frames, while unavailable source, published builds, native boundaries, native crashes, process exits, and launch failures remain truthfully distinct.