lang::typecheck::diagnostic

lang/src/typecheck/diagnostic.mo

Human-readable rendering for TypeError (lang/types.mo) — the type-checking counterpart to lang/parser/diagnostic.mo's render_parse_error, mirroring how the Rust reference splits parse vs. type diagnostics across rust/core/src/parser/error.rs and rust/core/src/eval/type.rs::type_error_as_diagnostics.

Unlike ParseError, TypeError carries no source location — but that is a fact about the ERROR, not about the AST. Terms DO carry locations (Term.ctx wrappers, built by the located parse that every path runs: see Term.ctx's own doc in lang/src/types.mo); none of them reaches a payload. type_check_located discards the location when the check FAILS (lang/src/typecheck/infer.mo's err e => err e), unify peels wrappers at entry (lang/src/typecheck/unify.mo), and the name-resolution variants — unknown_var, the most common diagnostic there is — have no term field to carry one at all. So a rendered TypeError can say which declaration failed and why, but not line:column the way a parse error can — render_type_error takes a context_name (typically a declaration's name) to stand in for that missing location. This is measured, not assumed: the five probes in lang/src/tests/unify_tests.mo pin it, including the nested-operand case, where a payload can have a bare root and a LOCATED child. Attaching the location at the innermost enclosing located node is the follow-up that would make ranges expression-granular; it is not attempted here.

defname_ref_to_string#
pub def name_ref_to_string (n : NameRef) : String

NameRef (lang/types.mo) has no Show/to-string helper of its own yet — the variants wrap Identifier/NamePath/QualifiedName/ Operator, each of which already has one.

deftype_error_message#
pub def type_error_message (e : TypeError) : String

A human-readable description of what went wrong — one line per TypeError variant (lang/types.mo:252).

defrender_type_error#
pub def render_type_error (context_name : String) (path : Option String) (e : TypeError) : String

Render a full diagnostic for a type error — same visual family as render_parse_error's header/arrow-line (lang/parser/diagnostic.mo), just without a line:col (see this file's header comment).

defrender_type_warning#
pub def render_type_warning (context_name : String) (path : Option String) (e : TypeError) : String

The warning sibling -- same header/arrow shape, severity word warning. e is usually a TypeError.custom: a warning is rendered message text the check path reports without rejecting (today, a non-exhaustive match's gap), not a demoted error.