lib+test: unify errors to Hare named-void tagged-union
Five tags from ref/hare/errors/common.ha — invalid, noaccess, noentry, exists, unsupported — all !void. lib/io keeps eof/closed as plain void (no Hare analogue for ww's singleton-style done) and adds underread. Drops errors.equal/isnil and the old str-sentinel surface.
This commit is contained in:
@@ -1252,33 +1252,54 @@ static const struct row rows[] = {
|
||||
" };\n"
|
||||
" return 0;\n"
|
||||
"};", 7 },
|
||||
/* errors.equal — sentinel comparison through a (T | error) union.
|
||||
* Sets up two errors, dispatches each, and confirms the matching
|
||||
* sentinel detection. */
|
||||
/* errors named-void tags — dispatch through a (T | tag | tag)
|
||||
* union, one variant per error condition. Replaces the old
|
||||
* errors.equal sentinel-string comparison. */
|
||||
{ "use errors;\n"
|
||||
"fn parse(n: i64) (i64 | errors.error) = {\n"
|
||||
" if (n < 0) { return errors.eof; };\n"
|
||||
" if (n == 0) { return errors.underread; };\n"
|
||||
"fn parse(n: i64) (i64 | errors.invalid | errors.noentry) = {\n"
|
||||
" if (n < 0) { let e: errors.invalid; return e; };\n"
|
||||
" if (n == 0) { let e: errors.noentry; return e; };\n"
|
||||
" return n;\n"
|
||||
"};\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let r1: (i64 | errors.error) = parse(-1);\n"
|
||||
" let r2: (i64 | errors.error) = parse(0);\n"
|
||||
" let r1: (i64 | errors.invalid | errors.noentry) = parse(-1);\n"
|
||||
" let r2: (i64 | errors.invalid | errors.noentry) = parse(0);\n"
|
||||
" let acc: i32 = 0;\n"
|
||||
" match (r1) {\n"
|
||||
" case let v: i64 => acc += -100;\n"
|
||||
" case let e: errors.error =>\n"
|
||||
" if (errors.equal(e, errors.eof)) { acc += 1; }\n"
|
||||
" else { acc += -100; };\n"
|
||||
" case let e: errors.invalid => acc += 1;\n"
|
||||
" case let e: errors.noentry => acc += -100;\n"
|
||||
" };\n"
|
||||
" match (r2) {\n"
|
||||
" case let v: i64 => acc += -100;\n"
|
||||
" case let e: errors.error =>\n"
|
||||
" if (errors.equal(e, errors.underread)) { acc += 10; }\n"
|
||||
" else { acc += -100; };\n"
|
||||
" case let e: errors.invalid => acc += -100;\n"
|
||||
" case let e: errors.noentry => acc += 10;\n"
|
||||
" };\n"
|
||||
" return acc;\n"
|
||||
"};", 11 },
|
||||
/* errors remaining named-void tags — pin the rest of the surface
|
||||
* (noaccess / exists / unsupported) so each is callable as both a
|
||||
* return variant and a match arm. One row per tag would bloat the
|
||||
* table; fold them into one (T | A | B | C) dispatch. */
|
||||
{ "use errors;\n"
|
||||
"fn classify(n: i32) (i32 | errors.noaccess | errors.exists | errors.unsupported) = {\n"
|
||||
" if (n == 1) { let e: errors.noaccess; return e; };\n"
|
||||
" if (n == 2) { let e: errors.exists; return e; };\n"
|
||||
" if (n == 3) { let e: errors.unsupported; return e; };\n"
|
||||
" return n;\n"
|
||||
"};\n"
|
||||
"fn dispatch(r: (i32 | errors.noaccess | errors.exists | errors.unsupported)) i32 = {\n"
|
||||
" match (r) {\n"
|
||||
" case let v: i32 => return v;\n"
|
||||
" case let e: errors.noaccess => return 10;\n"
|
||||
" case let e: errors.exists => return 20;\n"
|
||||
" case let e: errors.unsupported => return 30;\n"
|
||||
" };\n"
|
||||
" return -1;\n"
|
||||
"};\n"
|
||||
"fn main() i32 = {\n"
|
||||
" return dispatch(classify(1)) + dispatch(classify(2)) + dispatch(classify(3));\n"
|
||||
"};", 60 },
|
||||
/* bufio.readline: drain successive '\\n'-terminated lines from a
|
||||
* pre-filled buffer, then a trailing fragment that returns the
|
||||
* `linerr` variant carrying \"no newline\" (10 chars). */
|
||||
|
||||
Reference in New Issue
Block a user