1.4 KiB
1.4 KiB
PR-018 - PBS Result Flow (ok/err/handle) Rule Enforcement
Briefing
Result-flow rules are only partially enforced. This PR enforces allowed positions for ok/err, error-label validation, and handle arm terminal form requirements.
Motivation
Result-flow constructs are normative control-flow surfaces and must not behave as unconstrained expressions.
Target
ok(...)anderr(...)validation in return-flow contexts.handlesemantic validation, including terminal form of block arms.
Scope
- Restrict
ok/errto allowed result-flow positions. - Validate
err(E.case)against declared error type. - In
handleblock arms, enforce terminalok(payload)orerr(E2.case).
Method
- Add expression-use/context flags for result-flow forms.
- Add dedicated diagnostics for invalid placement and invalid error labels.
- Add terminal-check pass for handle block arms.
Acceptance Criteria
ok/erroutside allowed positions are rejected deterministically.return ok/errvalidates declaredresult<E>contract.handleblock arms violating terminal rules are rejected deterministically.- Existing propagate (
!) and handle exhaustiveness checks remain stable.
Tests
- Add positive and negative fixtures for
return ok/err. - Add invalid-position tests for
ok/erras ordinary expression. - Add
handlearm terminal-form tests.
Non-Goals
- New result syntax.
- Runtime trap policy changes.