flan/test/programs/error.flan
Joseph Ferano 18db822095 error, which is the signal a handler has to answer
spec-conditions.md §2. The same lookup as signal, and the difference is
entirely what happens when the walk ends: signal returns Unit and the
signalling function carries on, error has type Never and the program stops.
Only a transfer gets past it, so emit puts a guard after the call and then
unreachable - and flan_error cannot be marked noreturn for the same reason, it
does return, on exactly one path.

Being Never is what lets it stand where a value was expected, which is the
fall-through shape §1's load-texture example needs and the reason it is worth
having before the break loop rather than after. An unhandled one names the
condition on stderr and dies the way every other trap does; flan_error is where
the dev-build break loop will go.

The two spellings share one AST and IR node with a kind beside them, the same
shape Ast.unwrap already uses for some and try, because they differ in one
decision and nothing else. test/programs/error.flan is the unhandled case,
asserted on the exit code and the reason rather than through the outputs table,
which only has room for a program that exits 0.
2026-09-11 09:10:59 +07:00

15 lines
615 B
Plaintext

;;;; An unhandled (error c) — spec-conditions.md §2.
;;;;
;;;; Its argument is the whole of the difference from signal: a handler that
;;;; returns normally has not answered an error, so with nothing transferring
;;;; the program stops and says which condition it was. In a dev build this is
;;;; where the break loop will go.
(defstruct AssetMissing [id i32])
(defn main [] i32
;; A handler that returns normally. It runs — signal's lookup is the same —
;; and it still does not answer the error.
(handler-bind [(AssetMissing [c] (print-line "handler ran"))]
(error (AssetMissing {:id 1})))
0)