Master the fundamental concepts of semantic analysis through this focused micro-challenge.
Rust's mismatched types with expected/found labels, Clang's caret diagnostics, and Elm's friendly errors all come from deliberate semantic error design. A compiler that prints error with no location or context is worse than no compiler at all.
Include: what went wrong, where (file, line, column), and often a hint. Use consistent formatting. Continue after non-fatal errors to report multiple issues. Attach notes for related locations (declaration site vs use site).
cLoading…
foo?)Production compilers embed this step inside a longer pipeline. GCC flows through cpp, cc1, assembly, and ld; Clang uses the driver, Sema, LLVM IR passes, and a target backend. LLVM bitcode, JVM bytecode, and WASM are other familiar IRs at the same layer. The exercise isolates one pass so you can test it alone before chaining it to the next stage.
You will implement semantic error reporting with clear messages and source locations. This exercise asks you to format type and scope errors so users can fix their code without guessing what the compiler meant.
Implement a comprehensive semantic error reporting system.
Create an error reporting infrastructure:
SemanticError struct with severity, location, messageImplement error detectors for:
Implement warning detection:
Create formatted output:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github