Repository navigation
Description
Summary
Add tests for the user-visible presentation surface promised by §10.8 error declarations. The compiler already supports error declarations and error ... from conversion well enough for control-flow tests, but the campaign found Debug/Display behavior unpinned and the Error trait surface absent or incomplete. This issue should become the coverage and verification task for generated error formatting traits, while implementation of missing trait machinery remains with the error-trait issue.
Spec
§10.8 Error Declarations:
error ParseError =
UnexpectedChar(pos: usize, got: u8)
UnexpectedEof
InvalidNumber(pos: usize)
Normative requirement: error declarations automatically implement Error, Debug, and Display (docs/with-specification.md:4397-4407). §10.9 then says error AppError from IoError, ParseError, DbError generates wrapper variants and From implementations (docs/with-specification.md:4408-4416); those wrapper variants should also participate in the same debug/display/error presentation story.
Current state
test/behavior/behav_error_decl.w:5-34covers basicerrordeclarations, generated wrapper variants fromerror ... from, and?conversion into the wrapper error. It does not print or format the errors.test/behavior/behav_error_handling.w:6-70covers matching and ordinary Result flows for error enums. It also does not test Debug, Display, or anErrortrait bound.lib/std/traits.w:21-26declaresDebugandDisplaytraits for formatting, with primitiveDebugimpls beginning atlib/std/traits.w:120.lib/std/result.w:21definesContextError[E], anddocs/with-specification.md:4331-4342expectsContextError[E]to implementErrorwhenE: Error; this depends on a coherentErrortrait surface.src/MirLower.w:2050-2098lowers f-string formatting tofmt_to_str,fmt_debug_str,fmt_debug, andfmt_specintrinsics.src/CodegenDispatch.w:2346-2459implements debug formatting in codegen.src/CodegenDispatch.w:2359notes that enums use compiler-generated variant formatting for now, which is likely the current path for error debug output.out/req-campaign/g05.tsvrecords10.8.1.1|partial|gap|NEW:error-trait|NEW:tests-error-decls|Debug/Display work, untested; Error absent. That means this issue is test coverage plus verification, not the full trait-design implementation ifErroris still missing.
Implementation plan
- Add or extend a behavior test, preferably
test/behavior/behav_error_decl_formatting.w, focused onerrorpresentation. - Define an error with both payload and payload-less variants, for example
error ParseError = Bad(pos: usize) | Eof, and a wrappererror AppError from ParseError. - Exercise debug formatting with
f"{err:?}"for payload and payload-less variants. Assert stable strings that include the error type/variant and payload values. If the current compiler-generated enum formatter uses a different but intentional spelling, document that spelling in the test comments and make the issue body precise before implementation. - Exercise display formatting with
f"{err}"or an explicitDisplay.to_stringcall once the Display surface is implemented for errors. If Display is not implemented yet, keep this test in the issue plan and link the failing expectation to the error-trait implementation issue rather than silently weakening §10.8. - Add a generic helper requiring the eventual
Errortrait, such asfn accepts_error[E: Error](e: E) -> str, onceErrorexists inlib/std/traits.wor the appropriate std module. The helper should compile for generated error types and wrapper errors. - Keep
test/behavior/behav_error_decl.was the conversion/control-flow test; do not overload it with formatting assertions unless that makes the suite simpler.
Test plan
test/behavior/behav_error_decl_formatting.wwith//! expect-stdout: ok:f"{ParseError.Bad(9):?}"or equivalent debug path returns the chosen stable debug spelling.f"{ParseError.Eof:?}"covers payload-less variants.f"{AppError.Parse(ParseError.Bad(9)):?}"covers wrapper variants generated byerror ... from.- Display formatting for the same values returns the user-facing spelling required by the final Error/Display design.
- A generic
E: Errorhelper accepts the generated error type and wrapper type after theErrortrait exists.
- If Display or Error is not implemented at the time this issue is picked up, add compile-error tests that capture the current missing trait only in the implementation issue for
NEW:error-trait; this coverage issue should close only when the §10.8 contract passes.
Acceptance criteria
- Error declarations have behavior coverage for generated Debug formatting
- Error declarations have behavior coverage for generated Display formatting
- Generated wrapper errors from
error ... fromare covered - Generated error types satisfy the standard
Errortrait once that trait exists - Tests do not paper over a missing
Errortrait by checking only enum pattern matching -
with build && with build :fixpoint && with build :testpass
Dependencies
Depends on the error-trait implementation issue referenced in out/req-campaign/g05.tsv as NEW:error-trait if the Error trait is still absent when work starts. Overlaps #434, which owns the implementation side of error declarations and conversions.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 10.8.1.1.
Activity
ehartford commentedon Jul 3, 2026
Closing — error enum Debug (
{:?}) and Display ({}) formatting for payload and payload-less variants pinned by behav_error_decl_formatting (bfe7865); the Error/Debug/Display trait surface already covered by spec_ss10_8_error_trait, issue65_*. §10.Fix #530 tailrec verifier + coverage-sweep batch 3 (#498 #508 #517 #523