Canonical skill for creating or updating Scala 3 error-code docs in
docs/_docs/reference/error-codes/.
This file is the single source of truth. Keep other related files as pointers.
- Prefer full mechanical validation with
project/scripts/checkErrorCodeSnippets.scala. - If the environment blocks full validation, still produce the best draft possible and clearly mark what was not verified.
- If a code is not reproducible from pure Scala snippets, follow the non-reproducible path
below and keep
NonReproducibleErrorCodesaligned inproject/scripts/checkErrorCodeSnippets.scala.
Use this template for each E###.md page:
---
title: E###: <Short Title>
kind: Error
# since: 3.x.y # required when code > E166
# until: 3.x.y # required when the compiler ID is inactive
---
# E###: <Short Title>
<Explain when this diagnostic happens and why.>
## Example
```scala sc:fail sc-opts:-explain
<minimal snippet that triggers only E###>
```
### Error
```scala sc:nocompile
-- [E###] <Error|Warning>: example.scala:<line>:<col> -------------------------
<exact checker output here, including explanation text when present>
```
### Solution
```scala sc:compile
<direct fix of the example above>
```
<!-- SOURCE-ONLY: Remove the notice below once this page has been manually updated. -->
<aside class="warning">
This reference page was created with LLM assistance - the description of the error code may not be accurate or cover all possible scenarios.
</aside>For warning diagnostics, normally make the example fail under -Werror:
<warning-producing snippet>- Establish target metadata.
- Find the compiler ID in
compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala. - Use filename
docs/_docs/reference/error-codes/E###.md. - Set frontmatter
titleandkind(ErrororWarning). - Add
sincewhenerrorNumber > 166. - Add
untilwhen the ID is inactive.
- Draft from a nearby entry.
- Keep section order:
## Example,### Erroror### Warning,### Solution. - Keep snippets minimal and deterministic.
- Keep solutions as direct fixes of the failing scenario.
- Apply snippet marker rules.
- Example:
sc:fail(orcustom-sc:failonly when required). - Output block:
sc:nocompile. - Solution:
sc:compile(orcustom-sc:compileonly when required). - Include needed flags in snippet options (
sc-opts:-explain,sc-opts:-Werror, etc.).
- Keep output faithful.
- Store exact compiler output with
[E###]. - Include explain text when emitted.
- Keep indexing consistent.
- Add new files to
docs/sidebar.ymlunderError Codesin numeric order.
From repository root:
DOC=docs/_docs/reference/error-codes/E###.mdOne-time local compiler setup (rerun only when artifacts/version change):
sbtn scala3-bootstrapped/publishLocalCache local bootstrapped version:
VERSION_CACHE=/tmp/scala3-bootstrapped-version.txt
version=$(BOOTSTRAPPED_VERSION_CACHE="$VERSION_CACHE" project/scripts/get-bootstrapped-version.sh --refresh)
# later runs:
# version=$(BOOTSTRAPPED_VERSION_CACHE="$VERSION_CACHE" project/scripts/get-bootstrapped-version.sh)Refresh ### Error / ### Warning output:
scala --server=false --scala-version "$version" \
project/scripts/checkErrorCodeSnippets.scala -- "$DOC" --update-outputRun full validation:
scala --server=false --scala-version "$version" \
project/scripts/checkErrorCodeSnippets.scala -- "$DOC" --verboseExpected guarantees when validation runs:
- Example snippets fail and include the documented
E###. - Unexpected extra error codes are rejected.
- Output block matches compiler output.
- Solution snippets compile cleanly (
-Werrorenforced by checker).
- Frontmatter and heading match
E###. - Examples produce only the documented code (or are explicitly non-reproducible).
- Output block includes exact checker output.
- Solutions resolve the same scenario and compile without warnings.
- Sidebar entry exists and is ordered.