Skip to main content

Diagnostics

Mux reports two kinds of compiler diagnostic: errors and warnings. An error means the program is invalid and compilation stops. A warning means the program is valid, but the analyzer proved that part of it is redundant, unreachable, unused, or otherwise likely to be a defect.

Every diagnostic has a stable code. The English message may include names and types from your source, but the code does not change when that detail changes. Notes, labels, help text, and fix-its are attached to an error or warning.

Error and warning codes

The registry is owned by mux-compiler. Codes are never reused.

CodeKindTriggerExampleFix
E0100ErrorUnexpected lexer character?Remove or replace it
E0101ErrorUnterminated string"helloClose the string
E0102ErrorUnknown string escape"hi\z"Use a supported escape
E0103ErrorUnterminated block comment/* noteAdd */
E0104ErrorInvalid number literal12abcCorrect or separate it
E0105ErrorRange literal syntax0..10Use range(0, 10)
E0106ErrorInvalid character literal'ab'Use one character and close it
E0200ErrorMissing parser tokenfunc main( {Add the expected token
E0201ErrorMissing expressionif { ... }Write the expression
E0202ErrorMissing typereturnsAdd the type
E0203Errorbreak or continue outside a loopbreakMove it into a loop
E0204Errorreturn outside a functionreturn 42Put it in a function
E0205ErrorParser recovery reached 100 errorsmalformed sourceFix the earliest errors
E0300ErrorUndefined nameprint(missing)Declare, import, or rename it
E0301ErrorDuplicate declarationauto x = 1 twiceRename or assign instead
E0302ErrorType mismatchint n = "hello"Use a matching type
E0303ErrorWrong call argument countadd(1)Add or remove arguments
E0304ErrorMissing return on a reachable pathnon-void if without elseReturn on every path
E0305ErrorNon-exhaustive matchone arm for many valuesAdd arms or _
E0306ErrorAssignment to a non-assignable valueassigning to constUse a mutable binding
E0307ErrorUnknown field or methodvalue.missing()Correct the member name
E0308ErrorInvalid operator operandstrue + falseUse compatible operands
E0309ErrorInvalid match patternwrong enum patternMatch the value's type
E0310ErrorInvalid generic argumentslist<int, string>Use the declared arity
E0311ErrorRead before assignmentint value then print(value)Initialize it on every path
E0312ErrorDivision or modulo by a provable zero10 / 0Use a non-zero divisor
E0313ErrorNamed nested function captures a localnested inner uses outer's localPass it as a parameter or use a lambda
E0400ErrorModule cannot be foundimport missingCorrect the path or add it
E0401ErrorImported module cannot be loadedbroken imported fileFix that module
E0600RuntimeList index out of boundsitems[99]Use an index in range
E0601RuntimeMissing map keyvalues["missing"]Check membership first
E0602RuntimeDivision or modulo by zeron / 0Use a non-zero divisor
E0603RuntimeAssertion failureassert(false, "bad")Fix the failed invariant
E0604RuntimeWhere-constraint violationinvalid constrained valueSatisfy the constraint
E0605RuntimeInteger overflowchecked arithmetic overflowUse a safe range or type
E0699RuntimeInternal runtime failureruntime invariant failureReport the complete output
E0900ErrorInternal compiler failurecompiler bugReport the complete output
W0300WarningUnused bindingauto unused = 1Remove it, use it, or write _
W0301WarningShadowed bindinginner auto x hides outer xRename the inner binding
W0302WarningUnreachable codeafter returnRemove or move it
W0303WarningDead assignmentx = 1 then x = 2Remove the overwritten assignment
W0305WarningProvably constant conditionif 1 == 1Remove it or use runtime data
W0306WarningSafe redundant constructvalue && true or equivalentApply the suggested simplification

Warning rules are added only when the analyzer can prove the result. Mux does not use warnings for style preferences, guesses about performance, or ignored return values. A bare _ is the intentional unused-binding escape hatch. _name is an ordinary identifier.

W0300, W0301, and W0303 are emitted only after successful semantic analysis. W0304 is reserved: an actual read before assignment is the error E0311, so the compiler does not downgrade it to a warning.

Runtime failures are terminating diagnostics from the separately built runtime. They use the E06xx registry above and preserve a source location when the compiler has one.

mux explain

The compiler embeds the same registry used by diagnostics, so code lookup does not need a network connection:

mux explain E0302
mux explain W0302

The command prints the trigger, a small example, why the diagnostic exists, and the recommended fix. Unknown codes fail with a short command-line error.

Recovery and output limits

The parser keeps the valid prefix of the AST while it tries to recover after a syntax error. It continues with independent declarations when that is safe. Semantic analysis and code generation do not run after a parse failure, so syntax errors cannot create later code-generation failures.

Mux emits at most 100 diagnostics in one batch. If more are available, the output ends with an explicit truncation message containing the number omitted. Diagnostics are sorted by file, source position, severity, and code, so output is stable across runs.

Code generation never runs when syntax errors remain. Runtime panics are a separate terminating failure channel from compiler diagnostics, but use the runtime E06xx registry described above.

Denying warnings

Pass --deny-warnings to keep warning output while making warnings fail the compile:

mux build app.mux --deny-warnings

The check happens before code generation, linking, or running the program.

mux fix

Preview or apply safe compiler edits with:

mux fix app.mux --dry-run
mux fix app.mux
mux fix app.mux --format json

mux fix applies only machine-applicable edits. Each edit includes a file, byte range, replacement text, and applicability. The compiler rejects overlapping edits and edits that touch recovered source. Help text such as “did you mean” is not treated as an edit. If the current compiler has no proven safe edit for a diagnostic, the command reports that no fixes are available and leaves the source unchanged.

Before writing anything, Mux will apply the edits in memory, reparse every affected module, and run analysis again. Failed validation will leave the source unchanged and report the proposed edits for inspection. Successful writes will be atomic and may cover more than one file.

An edit is machine-applicable only when the compiler can prove that it preserves meaning. Suggestions that need a human decision remain ordinary help text and are never applied automatically.