45 lines
1.4 KiB
Markdown
45 lines
1.4 KiB
Markdown
# 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(...)` and `err(...)` validation in return-flow contexts.
|
|
- `handle` semantic validation, including terminal form of block arms.
|
|
|
|
## Scope
|
|
|
|
- Restrict `ok/err` to allowed result-flow positions.
|
|
- Validate `err(E.case)` against declared error type.
|
|
- In `handle` block arms, enforce terminal `ok(payload)` or `err(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/err` outside allowed positions are rejected deterministically.
|
|
- `return ok/err` validates declared `result<E>` contract.
|
|
- `handle` block 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/err` as ordinary expression.
|
|
- Add `handle` arm terminal-form tests.
|
|
|
|
## Non-Goals
|
|
|
|
- New result syntax.
|
|
- Runtime trap policy changes.
|