raz / commit 7916b9fd

commit
7916b9fd3aada0225b54cdb9961eec720c2d57f2
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
ed43cacf
try: return an error that is not nil from the procedure it stands in

Report 2026-10.20, section 7.8: try c calls c, whose last result is an
ERROR, and if that is not nil the procedure returns it, with zeros for
its other results, after the deferred statements; else it is the
call's other results. A statement, an operand, or the right of a
multiple assignment. try is a reserved word.

The seed: sTry in scan, TryCall in parse, TryAlign and TryReturn in
gen, which make no entry on the stack of values, so try can stand in
the middle of an expression. conform/ has Try and twelve errors;
test/err has the dropped values. The tutorial's Errors and the tour's
Layers use it. The keyword lists of tools, self/, vim, emacs, the
site and raz(7) know try.

patch · log

51 files changed, +845 -63

CLAUDE.md modified +2 -1

@@ -102,7 +102,8 @@
102102 defect, and the library grows only by what breaks no program written
103103 for it. A wish for more, the owner's or yours, goes on the list in
104104 `PLAN.md`, for a later thaw; it isn't built. v0.6.0 was such a thaw,
105-by the owner's word: report 2026-10.12; the compiler follows 2026-10.19,
105+by the owner's word: report 2026-10.12; the compiler follows 2026-10.20, whose `try` returns an error that isn't
106+nil from the procedure it stands in (10.20, the owner's word), and 2026-10.19,
106107 whose `Sys` writes without waiting, for rat's pastes (10.13), and
107108 whose blank, `_ := f(x)`, drops a result that is otherwise warned of
108109 (10.14), and whose `Math` has `pow`, the logarithms to 2 and 10,

PLAN.md (history) modified +4 -0

@@ -17,6 +17,10 @@
1717 compiler lives in `self/`, one raz module to a seed unit, the same
1818 names, and has its own targets; nothing in `src/` or `lib/` changes.
1919
20+The language gained `try` (report 2026-10.20) for this: the parser's
21+errors will return an `ERROR` that `try` passes up, and `self/Jump.raz`,
22+which the scanner's `fail` uses now, goes when step 4 lands.
23+
2024 Each unit is ported in the seed's order (leaves first) and tested on
2125 its own against the seed's, on the same inputs, since no program can
2226 link both. The language and the library are frozen: a gap found goes

conform/err/TryConversion.raz (history) added +8 -0

@@ -0,0 +1,8 @@
1+module TryConversion;
2+var n: INT;
3+proc g: ERROR;
4+begin
5+ n := try INT(n);
6+ return nil;
7+end;
8+end TryConversion.

conform/err/TryCount.raz (history) added +12 -0

@@ -0,0 +1,12 @@
1+module TryCount;
2+proc f: (INT, ERROR);
3+begin
4+ return 1, nil;
5+end;
6+proc g: ERROR;
7+var a, b: INT;
8+begin
9+ a, b := try f();
10+ return nil;
11+end;
12+end TryCount.

conform/err/TryDeferred.raz (history) added +11 -0

@@ -0,0 +1,11 @@
1+module TryDeferred;
2+proc f: ERROR;
3+begin
4+ return nil;
5+end;
6+proc g: ERROR;
7+begin
8+ defer try f();
9+ return nil;
10+end;
11+end TryDeferred.

conform/err/TryInBody.raz (history) added +8 -0

@@ -0,0 +1,8 @@
1+module TryInBody;
2+proc f: ERROR;
3+begin
4+ return nil;
5+end;
6+begin
7+ try f();
8+end TryInBody.

conform/err/TryInMain.raz (history) added +10 -0

@@ -0,0 +1,10 @@
1+module TryInMain;
2+proc f: ERROR;
3+begin
4+ return nil;
5+end;
6+proc main*;
7+begin
8+ try f();
9+end;
10+end TryInMain.

conform/err/TryNeedsArguments.raz (history) added +11 -0

@@ -0,0 +1,11 @@
1+module TryNeedsArguments;
2+proc f(n: INT): ERROR;
3+begin
4+ return nil;
5+end;
6+proc g: ERROR;
7+begin
8+ try f;
9+ return nil;
10+end;
11+end TryNeedsArguments.

conform/err/TryNoValue.raz (history) added +12 -0

@@ -0,0 +1,12 @@
1+module TryNoValue;
2+proc f: ERROR;
3+begin
4+ return nil;
5+end;
6+proc g: ERROR;
7+var n: INT;
8+begin
9+ n := try f();
10+ return nil;
11+end;
12+end TryNoValue.

conform/err/TryNotACall.raz (history) added +8 -0

@@ -0,0 +1,8 @@
1+module TryNotACall;
2+var n: INT;
3+proc g: ERROR;
4+begin
5+ try n;
6+ return nil;
7+end;
8+end TryNotACall.

conform/err/TryNotError.raz (history) added +11 -0

@@ -0,0 +1,11 @@
1+module TryNotError;
2+proc f: INT;
3+begin
4+ return 1;
5+end;
6+proc g: ERROR;
7+begin
8+ try f;
9+ return nil;
10+end;
11+end TryNotError.

conform/err/TryReturnsNothing.raz (history) added +10 -0

@@ -0,0 +1,10 @@
1+module TryReturnsNothing;
2+proc f;
3+begin
4+end;
5+proc g: ERROR;
6+begin
7+ try f();
8+ return nil;
9+end;
10+end TryReturnsNothing.

conform/err/TrySeveralValues.raz (history) added +12 -0

@@ -0,0 +1,12 @@
1+module TrySeveralValues;
2+proc f: (INT, INT, ERROR);
3+begin
4+ return 1, 2, nil;
5+end;
6+proc g: ERROR;
7+var n: INT;
8+begin
9+ n := try f();
10+ return nil;
11+end;
12+end TrySeveralValues.

conform/err/TryWrongResults.raz (history) added +11 -0

@@ -0,0 +1,11 @@
1+module TryWrongResults;
2+proc f: ERROR;
3+begin
4+ return nil;
5+end;
6+proc g: (INT, BOOL);
7+begin
8+ try f();
9+ return 1, true;
10+end;
11+end TryWrongResults.

conform/run/Try.expect (history) added +23 -0

@@ -0,0 +1,23 @@
1+one 4: 0 ok, log 92
2+one -1: 0 bad, log 0
3+one 0: 0 worse, log 0
4+two 8: 13 ok, log 0
5+two 0: 0 worse, log 0
6+many 3: 9 ok, log 0
7+15
8+many -2: 0 bad, log 0
9+0
10+whole 4: 49 ok, log 0
11+whole -4: 0 bad, log 0
12+deferred 6: 103 ok, log 21
13+deferred 0: 0 worse, log 21
14+among 4 6: 123 ok, log 3
15+among 4 0: 0 worse, log 3
16+among 0 6: 0 worse, log 3
17+shortcut 3: 0 bad, log 0
18+shortcut 0: 0 ok, log 0
19+through 3: 0 ok, log 0
20+through -3: 0 bad, log 0
21+loop 5 3: 12 ok, log 0
22+loop 2 3: 0 ok, log 0
23+loop 5 -2: 0 bad, log 0

conform/run/Try.raz (history) added +178 -0

@@ -0,0 +1,178 @@
1+module Try;
2+(* try: an error that isn't nil is returned, with zeros for the other
3+ results; else the call's other results are the value. Every shape of
4+ results, in expressions, among arguments, past deferred statements. *)
5+import Out;
6+
7+const
8+ Bad*: ERROR = "bad";
9+ Worse*: ERROR = "worse";
10+
11+type Pair = record a, b: I64; end;
12+
13+var
14+ log: INT; (* the deferred statements run, as digits *)
15+ handler: proc(n: INT): ERROR;
16+
17+(* fails when n is negative *)
18+proc check(n: INT): ERROR;
19+begin
20+ if n < 0 then return Bad; end;
21+ return nil;
22+end;
23+
24+(* two words: a value, and Worse when n is zero *)
25+proc half(n: INT): (INT, ERROR);
26+begin
27+ if n = 0 then return 7, Worse; end;
28+ return n div 2, nil;
29+end;
30+
31+(* several results, in a temporary *)
32+proc three(n: INT): (I64, I64, ERROR);
33+begin
34+ if n < 0 then return 5, 6, Bad; end;
35+ return I64(n), I64(n * 2), nil;
36+end;
37+
38+proc real(n: INT): (F64, ERROR);
39+begin
40+ if n < 0 then return 1.5, Bad; end;
41+ return F64(n) / 2.0, nil;
42+end;
43+
44+proc pair(n: INT): (Pair, ERROR);
45+begin
46+ if n < 0 then return {a: 1, b: 2}, Bad; end;
47+ return {a: I64(n), b: I64(n + 1)}, nil;
48+end;
49+
50+proc add(a, b, c: INT): INT;
51+begin
52+ return a * 100 + b * 10 + c;
53+end;
54+
55+proc yes(n: INT): (BOOL, ERROR);
56+begin
57+ if n < 0 then return true, Bad; end;
58+ return n > 5, nil;
59+end;
60+
61+proc setup: ERROR;
62+begin
63+ log := log * 10 + 9;
64+ return nil;
65+end;
66+
67+(* the enclosing procedure ends in a lone ERROR *)
68+proc one(n: INT): ERROR;
69+var h: INT;
70+begin
71+ try check(n);
72+ h := try half(n);
73+ try setup;
74+ log := log * 10 + h;
75+ return nil;
76+end;
77+
78+(* in two words *)
79+proc two(n: INT): (INT, ERROR);
80+begin
81+ return 1 + try half(n) * 3, nil;
82+end;
83+
84+(* behind a pointer *)
85+proc many(n: INT): (I64, F64, ERROR);
86+var a, b: I64; r: F64;
87+begin
88+ a, b := try three(n);
89+ r := try real(n);
90+ return a + b, r, nil;
91+end;
92+
93+(* a record result, so the results of the caller are behind a pointer *)
94+proc whole(n: INT): (Pair, I64, ERROR);
95+var p: Pair;
96+begin
97+ p := try pair(n);
98+ return p, p.a + p.b, nil;
99+end;
100+
101+(* deferred statements run on the way out, the error unchanged *)
102+proc deferred(n: INT): (INT, ERROR);
103+begin
104+ defer log := log * 10 + 1;
105+ defer log := log * 10 + 2;
106+ return try half(n) + 100, nil;
107+end;
108+
109+(* among the arguments of another call, with a value pushed already *)
110+proc among(n, m: INT): (INT, ERROR);
111+begin
112+ defer log := log * 10 + 3;
113+ return add(1, try half(n), try half(m)), nil;
114+end;
115+
116+(* only when its operand is evaluated *)
117+proc shortcut(n: INT): (BOOL, ERROR);
118+begin
119+ return (n > 0) and try yes(n - 1 - 100), nil;
120+end;
121+
122+proc through(n: INT): ERROR;
123+begin
124+ handler := check;
125+ try handler(n);
126+ return nil;
127+end;
128+
129+proc loop(n, off: INT): (INT, ERROR);
130+var i, sum: INT;
131+begin
132+ for i := 1 to n do
133+ if try yes(i + off) then sum := sum + try half(i * 2); end;
134+ end;
135+ return sum, nil;
136+end;
137+
138+proc flag(b: BOOL): INT;
139+begin
140+ if b then return 1; end;
141+ return 0;
142+end;
143+
144+proc show(what: []U8; v: INT; e: ERROR);
145+begin
146+ Out.str(what); Out.str(": "); Out.int(v);
147+ if e = nil then Out.str(" ok"); else Out.str(" "); Out.str(MSG(e)); end;
148+ Out.str(", log "); Out.int(log); Out.ln;
149+ log := 0;
150+end;
151+
152+proc main*;
153+var v: INT; e: ERROR; a: I64; f: F64; p: Pair; b: BOOL;
154+begin
155+ e := one(4); show("one 4", 0, e);
156+ e := one(-1); show("one -1", 0, e);
157+ e := one(0); show("one 0", 0, e);
158+ v, e := two(8); show("two 8", v, e);
159+ v, e := two(0); show("two 0", v, e);
160+ a, f, e := many(3); show("many 3", INT(a), e); Out.int(INT(f * 10.0)); Out.ln;
161+ a, f, e := many(-2); show("many -2", INT(a), e); Out.int(INT(f * 10.0)); Out.ln;
162+ p, a, e := whole(4); show("whole 4", INT(p.a * 10 + a), e);
163+ p, a, e := whole(-4); show("whole -4", INT(p.a * 10 + a), e);
164+ v, e := deferred(6); show("deferred 6", v, e);
165+ v, e := deferred(0); show("deferred 0", v, e);
166+ v, e := among(4, 6); show("among 4 6", v, e);
167+ v, e := among(4, 0); show("among 4 0", v, e);
168+ v, e := among(0, 6); show("among 0 6", v, e);
169+ b, e := shortcut(3); show("shortcut 3", flag(b), e);
170+ b, e := shortcut(0); show("shortcut 0", flag(b), e);
171+ e := through(3); show("through 3", 0, e);
172+ e := through(-3); show("through -3", 0, e);
173+ v, e := loop(5, 3); show("loop 5 3", v, e);
174+ v, e := loop(2, 3); show("loop 2 3", v, e);
175+ v, e := loop(5, -2); show("loop 5 -2", v, e);
176+end;
177+
178+end Try.

conform/run/Try.reals (history) added +0 -0

An empty file.

doc/compiler.md (history) modified +25 -0

@@ -1026,6 +1026,31 @@
10261026 the end, `return` and `break`. A `return`'s result waits in the frame
10271027 meanwhile, so that gen's stack is empty when they run.
10281028
1029+`try` (report 7.8) is `TryCall`, for the statement, an operand
1030+(`Factor`) and the right of a multiple assignment (`MultiAssign`). It
1031+reads the call as `Designator` does, takes the error, the last of its
1032+results, out of the way into a slot of the frame, and leaves in `x`
1033+the results that are left: none, one value, or a tuple of the others,
1034+`WithoutLast`. Then, in the code before and after, this:
1035+
1036+```
1037+ load [slot]; jz ok ; JumpIf(ok, false)
1038+ and rsp, -16 ; TryAlign, if a deferred statement is in force
1039+ call deferred... ; RunDefers(0), as for a return
1040+ mov rax/rdx or the results ; TryReturn(slot): zeros, and the error last
1041+ jmp exit
1042+ok: ...
1043+```
1044+
1045+Unlike `return`, which is a statement and finds gen's stack empty,
1046+`try` can stand in the middle of an expression, with values waiting
1047+on gen's stack and quadwords pushed for another call's arguments. The
1048+out-of-line code therefore makes no entry on the stack: `TryReturn`
1049+loads registers and jumps, and `TryAlign` makes the machine's stack
1050+even for the deferred statements, which expect it so. The code that
1051+follows is the code for an error that is nil, with the stack as it
1052+was, so no model needs resetting.
1053+
10291054 Then declarations: `Declarations` reads `const`, `type`, `var`, `proc`
10301055 and `extern`, each one through `Declaration`, a recovery point, which
10311056 calls `ConstDecl`, `TypeDecl`, `VarDecl`, `ProcDecl` or `ExternDecl`. `ProcDecl` handles forward declarations, code procedures

doc/raz-tutorial.7 (history) modified +40 -0

@@ -513,6 +513,16 @@
513513 return INT(n), nil;
514514 end;
515515
516+(* the sum of the numbers in words: the first error ends it *)
517+proc total(words: [][]U8): (INT, ERROR);
518+var i, sum: INT;
519+begin
520+ for i := 0 to LEN(words) - 1 do
521+ sum := sum + try number(words[i]);
522+ end;
523+ return sum, nil;
524+end;
525+
516526 proc main*;
517527 var words: [3][]U8; i, n: INT; err: ERROR;
518528 begin
@@ -525,6 +535,10 @@
525535 end;
526536 Out.ln;
527537 end;
538+ n, err := total(["1", "2", "3"]);
539+ Out.int(n); Out.ln;
540+ n, err := total(words);
541+ if err # nil then Out.str(MSG(err)); Out.ln; end;
528542 end;
529543
530544 end Errors.
@@ -533,6 +547,8 @@
533547 42
534548 empty
535549 not a number up to 1000
550+6
551+nothing to read
536552 .Ed
537553 .Pp
538554 A procedure that can fail returns an
@@ -550,6 +566,30 @@
550566 An exported one, as
551567 .Cm Empty
552568 is here, lets the callers tell it from the others.
569+.Pp
570+A caller that can't deal with an error passes it on to its own caller
571+with
572+.Cm try ,
573+as
574+.Cm total
575+does: if the call returned an error that isn't
576+.Cm nil ,
577+the procedure
578+.Cm try
579+stands in returns that error, with zero for its other results, and
580+otherwise
581+.Cm try
582+is the call's other results, here a number.
583+.Cm try
584+is a
585+.Cm return ,
586+written where the call is: it has no handler, keeps no state and
587+unwinds nothing, so every place a procedure can leave is in its text.
588+The procedure it stands in must itself end in an
589+.Cm ERROR ,
590+so
591+.Cm main ,
592+which returns none, tests each error and deals with it.
553593 raz has no exceptions.
554594 .Sh 9. DEFER
555595 .Bd -literal -offset indent

doc/raz.7 (history) modified +2 -2

@@ -63,8 +63,8 @@
6363 .Bd -literal -offset indent
6464 and begin break by code const defer div do else elsif end
6565 extern for forward if import in link match mod module not of
66-or packed proc record repeat return set shl shr then to type
67-until var variant VOLATILE while xor
66+or packed proc record repeat return set shl shr then to try
67+type until var variant VOLATILE while xor
6868 .Ed
6969 .Pp
7070 The basic types,

doc/raz.md (history) modified +124 -14

@@ -9,12 +9,13 @@
99 This report defines the language. It is short on purpose. Whatever it
1010 doesn't allow, raz doesn't have.
1111
12-This is version 2026-10.19 of the report; section 12 says what each
12+This is version 2026-10.20 of the report; section 12 says what each
1313 version changed. 2026-10.11 and 2026-10.12 are a thaw the owner chose,
1414 for a language anyone can build again. They break programs written
1515 for 2026-10.10 and before: for 2026-10.9, say, the report of compiler
1616 0.5.0, the last release before them; and 2026-10.12 breaks code
17-procedures written for 2026-10.11.
17+procedures written for 2026-10.11. 2026-10.20 is a third, for `try`
18+(section 7.8); it breaks a program that has a name `try`.
1819
1920 The language is frozen, softly, from this version on: it changes only
2021 to mend a defect, and its library grows only by what breaks no program
@@ -59,8 +60,8 @@
5960 ```
6061 and begin break by code const defer div do else elsif end extern for
6162 forward if import in link match mod module not of or packed proc record
62-repeat return set shl shr then to type until var variant VOLATILE while
63-xor
63+repeat return set shl shr then to try type until var variant VOLATILE
64+while xor
6465 ```
6566
6667 `static`, in `link static;` (section 3), isn't one.
@@ -499,6 +500,10 @@
499500 const NotFound*: ERROR = "not found";
500501 ```
501502
503+An `ERROR` is how a procedure says it failed: by convention the last
504+of its results, and `nil` when nothing failed. A caller that can't
505+deal with a failure itself passes it on with `try` (section 7.8).
506+
502507 `ERROR` is a basic type as big as an address. A value of it is made only
503508 by a constant declared as above, and each such declaration makes an
504509 error different from every other, whatever its message: two modules that
@@ -588,15 +593,16 @@
588593 | "not" Factor | "~" Factor
589594 | "[" [ Expr { "," Expr } ] "]"
590595 | "{" [ Element { "," Element } ] "}"
591- | "^" [ "VOLATILE" ] Type "(" Expr ")" .
596+ | "^" [ "VOLATILE" ] Type "(" Expr ")"
597+ | "try" Designator .
592598 Element = Expr | ident ":" Expr .
593599 Designator = QualIdent { Selector } .
594600 Selector = "." ident | "^" | "[" Expr [ ".." Expr ] "]"
595601 | "(" [ Expr { "," Expr } ] ")" .
596602 ```
597603
598-The operators bind in the order of the grammar: `not` and `~` most
599-tightly, then the multiplying operators, then the adding ones, then
604+The operators bind in the order of the grammar: `not`, `~` and `try`
605+(section 7.8) most tightly, then the multiplying operators, then the adding ones, then
600606 the relations, then `and`, then `or`. So `a + b * c = d` is
601607 `(a + (b * c)) = d`, `x & 0FH = 0` is `(x & 0FH) = 0`, and
602608 `i < n and a[i] # 0 or done` is `((i < n) and (a[i] # 0)) or done`. A
@@ -607,7 +613,7 @@
607613
608614 A pointer to a record isn't the record: its fields are `p^.f`, never
609615 `p.f`, and the elements of a pointer to an array are `p^[i]`. A
610-statement starts with a name, so `^T(x)^ := v` isn't one.
616+statement starts with a name or `try`, so `^T(x)^ := v` isn't one.
611617
612618 ### 6.1 Integers
613619
@@ -819,7 +825,8 @@
819825 | "match" Expr "of" { "|" Arm } "end"
820826 | "return" [ Expr { "," Expr } ]
821827 | "break"
822- | "defer" Statement .
828+ | "defer" Statement
829+ | "try" Designator .
823830 Arm = ( ident [ "(" ident { "," ident } ")" ]
824831 | Label { "," Label } | "else" ) ":" Statements .
825832 Label = Expr [ ".." Expr ] .
@@ -983,10 +990,105 @@
983990 ```
984991
985992 `return e;` evaluates `e` before the deferred statements run. A
986-deferred statement can't contain `return`, `break` or `defer` that
987-would leave it. A failed check, `Rt.exit` and `Sys.exit` end the
993+deferred statement can't contain `return`, `break`, `defer` or `try`
994+that would leave it. A failed check, `Rt.exit` and `Sys.exit` end the
988995 program without running the deferred statements still pending.
996+
997+### 7.8 Try
998+
999+A procedure that can fail returns an `ERROR` as its last result
1000+(section 5.8), `nil` when it didn't. A caller that can't deal with the
1001+failure passes it on to its own caller, which `try` does in a word:
9891002
1003+```
1004+proc total(words: [][]U8): (INT, ERROR);
1005+var i, sum: INT;
1006+begin
1007+ for i := 0 to LEN(words) - 1 do
1008+ sum := sum + try number(words[i]);
1009+ end;
1010+ return sum, nil;
1011+end;
1012+```
1013+
1014+`try c`, where `c` is a call (below) of a procedure whose last result
1015+is an `ERROR`, makes the call and looks at that error. If it is `nil`,
1016+the program goes on, and `try c` is what `c` returned without the
1017+error. If it isn't, the procedure `try` stands in returns at once, as
1018+`return` does (section 7.3): its last result is that error, and every
1019+other result is zero, as a variable of its type starts (section 4).
1020+Nothing more of the statement `try` stands in is done; in the example,
1021+`sum` isn't assigned. So
1022+
1023+```
1024+x := try f(a);
1025+```
1026+
1027+is, with `e` a variable the program can't name, and `0` standing for
1028+a zero of each of the procedure's other results:
1029+
1030+```
1031+x, e := f(a);
1032+if e # nil then return 0, e; end;
1033+```
1034+
1035+The error is the one `c` returned, and compares with `=` as it did
1036+there. `try` has no handler and keeps no state: it is a `return`,
1037+written where the call is, so that every place a procedure can leave is
1038+in its text. A program that means to deal with an error tests it, as
1039+section 5.8 shows.
1040+
1041+**What `try` is applied to.** `c` is a designator that ends in a call:
1042+`f(x)`, `Mod.f(x)`, `p^.next(x)`, or a call through a variable of
1043+procedure type. Where the procedure has no parameters its parentheses
1044+may be left out, as in a statement (section 7.1), and `try` calls it:
1045+`try setup;`. A conversion, a built-in procedure (section 6.8) and the
1046+case of a variant are written like calls and aren't procedures'; `try`
1047+can't be applied to them.
1048+
1049+**What `try c` is.** `c`'s results but the last.
1050+
1051+- With none, `try c` isn't a value and stands only as a statement:
1052+ `try flush;`.
1053+- With one, it is a value of that type, an operand wherever `c`
1054+ would be: `n := try number(s);`, `sum + try number(s)`,
1055+ `if try ready(fd) then`. Like `not`, it applies to the factor after
1056+ it: `try f(x) + 1` is `(try f(x)) + 1`.
1057+- With several, it stands only on the right of a multiple assignment,
1058+ as `c` itself would, with a target for each: `a, b := try f(x);`.
1059+
1060+As a statement, `try c;` drops the values of `c` that it has, and a
1061+dropped value is warned of as a call that drops a result is (section
1062+10); `_ := try c;` and `a, _ := try c;` say it is meant (section 7.1).
1063+The error is never dropped: `try` is the way of passing it on.
1064+
1065+**Where `try` may stand.** Every use of `try` is an error unless:
1066+
1067+- the procedure it stands in has an `ERROR` as its last result. A
1068+ module's body, and a procedure with no results, such as `proc
1069+ main*;`, have none: there an error is dealt with where it is found,
1070+ by a test;
1071+- the last result of the procedure `c` calls is an `ERROR`;
1072+- it is not inside a deferred statement, which `try` would leave
1073+ (section 7.7).
1074+
1075+A generic module is checked in each instance (section 3), so a
1076+procedure of an instance whose last result, by its type arguments, is
1077+no `ERROR` and uses `try` is an error in that instance.
1078+
1079+**Order.** The arguments of `c` are evaluated from left to right, then
1080+`c` is called, and then its error is looked at (section 7.5). The
1081+designators on the left of an assignment are evaluated before its
1082+right side as always, so in `a[i()] := try g()`, `i` is called, then
1083+`g`; if `g` fails, nothing is assigned. A `try` in the right operand
1084+of `and` or `or` is reached only when that operand is evaluated
1085+(section 6.2).
1086+
1087+**Deferred statements.** When `try` returns, the statements deferred
1088+in the procedure and not yet run are run, the last first, as for a
1089+`return` (section 7.7), after the error and the zero results have been
1090+chosen; no deferred statement can change them.
1091+
9901092 ## 8. Procedures
9911093
9921094 ```
@@ -1016,7 +1118,9 @@
10161118 that returns several values can only stand on the right of a multiple
10171119 assignment, alone as a statement, or alone after `return` in a
10181120 procedure whose results are of the same types, in the same order,
1019-which then returns them as they are: `return divmod(n, 2);`.
1121+which then returns them as they are: `return divmod(n, 2);`. A
1122+procedure that can fail has an `ERROR` as its last result (section
1123+5.8), which `try` passes on (section 7.8).
10201124
10211125 ```
10221126 module Divide;
@@ -1933,6 +2037,10 @@
19332037 - **2026-10.18.** A code procedure takes and returns slices (section
19342038 8).
19352039 - **2026-10.19.** The library gains `Bytes` (section 11).
2040+- **2026-10.20.** `try`: a call of a procedure whose last result is an
2041+ `ERROR`, which makes the procedure it stands in return that error
2042+ when it isn't `nil` (sections 2, 5.8, 6, 7.8 and appendix B). `try`
2043+ becomes a reserved word, which breaks a program with a name `try`.
19362044
19372045 ## Appendix A. What an implementation chooses
19382046
@@ -2057,7 +2165,8 @@
20572165 | "not" Factor | "~" Factor
20582166 | "[" [ Expr { "," Expr } ] "]"
20592167 | "{" [ Element { "," Element } ] "}"
2060- | "^" [ "VOLATILE" ] Type "(" Expr ")" .
2168+ | "^" [ "VOLATILE" ] Type "(" Expr ")"
2169+ | "try" Designator .
20612170 Element = Expr | ident ":" Expr .
20622171 Designator = QualIdent { Selector } .
20632172 Selector = "." ident | "^" | "[" Expr [ ".." Expr ] "]"
@@ -2075,7 +2184,8 @@
20752184 | "match" Expr "of" { "|" Arm } "end"
20762185 | "return" [ Expr { "," Expr } ]
20772186 | "break"
2078- | "defer" Statement .
2187+ | "defer" Statement
2188+ | "try" Designator .
20792189 Arm = ( ident [ "(" ident { "," ident } ")" ]
20802190 | Label { "," Label } | "else" ) ":" Statements .
20812191 Label = Expr [ ".." Expr ] .

editor/emacs/raz-mode.el (history) modified +2 -2

@@ -24,8 +24,8 @@
2424 '("and" "begin" "break" "by" "code" "const" "defer" "div" "do" "else"
2525 "elsif" "end" "extern" "for" "forward" "if" "import" "in" "link"
2626 "match" "mod" "module" "not" "of" "or" "packed" "proc" "record"
27- "repeat" "return" "set" "shl" "shr" "then" "to" "type" "until" "var"
28- "variant" "VOLATILE" "while" "xor"))
27+ "repeat" "return" "set" "shl" "shr" "then" "to" "try" "type" "until"
28+ "var" "variant" "VOLATILE" "while" "xor"))
2929
3030 (defconst raz-types
3131 '("I8" "I16" "I32" "I64" "INT" "UINT" "U8" "U16" "U32" "U64" "BOOL" "F32" "F64" "ERROR"))

editor/vim/syntax/raz.vim (history) modified +2 -2

@@ -10,8 +10,8 @@
1010 syntax keyword razKeyword and begin break by code const defer div do else
1111 syntax keyword razKeyword elsif end extern for forward if import in link
1212 syntax keyword razKeyword match mod module not of or packed proc record
13-syntax keyword razKeyword repeat return set shl shr then to type until var
14-syntax keyword razKeyword variant VOLATILE while xor
13+syntax keyword razKeyword repeat return set shl shr then to try type until
14+syntax keyword razKeyword var variant VOLATILE while xor
1515 syntax keyword razType I8 I16 I32 I64 INT UINT U8 U16 U32 U64 BOOL F32 F64 ERROR
1616 syntax keyword razBuiltin SIZE ADR LEN NEW MSG SYSCALL FENCE CAS XCHG XADD
1717 syntax keyword razBuiltin ARGC ARGV INC DEC

self/Scan.raz modified +4 -3

@@ -26,7 +26,7 @@
2626 sAnd, sBegin, sBreak, sBy, sCode, sConst, sDefer, sDiv, sDo, sElse,
2727 sElsif, sEnd, sExtern, sFor, sForward, sIf, sImport, sIn, sLink,
2828 sMatch, sMod, sModule, sNot, sOf, sOr, sPacked, sProc, sRecord,
29- sRepeat, sReturn, sSet, sShl, sShr, sThen, sTo, sType, sUntil, sVar,
29+ sRepeat, sReturn, sSet, sShl, sShr, sThen, sTo, sTry, sType, sUntil, sVar,
3030 sVariant, sVolatile, sWhile, sXor,
3131 sEof);
3232
@@ -47,14 +47,15 @@
4747 const
4848 MaxIdent* = 63;
4949 MaxStr* = 65536;
50- NumWords = 42;
50+ NumWords = 43;
5151 NumOps = 28;
5252 words: [NumWords][]U8 = [
5353 "and", "begin", "break", "by", "code", "const", "defer", "div", "do",
5454 "else", "elsif", "end", "extern", "for", "forward", "if", "import",
5555 "in", "link", "match", "mod", "module", "not", "of", "or", "packed",
5656 "proc", "record", "repeat", "return", "set", "shl", "shr", "then",
57- "to", "type", "until", "var", "variant", "VOLATILE", "while", "xor"];
57+ "to", "try", "type", "until", "var", "variant", "VOLATILE", "while",
58+ "xor"];
5859 (* sPlus to sBlank *)
5960 ops: [NumOps][]U8 = [
6061 "+", "-", "*", "/", "=", "#", "<", "<=", ">", ">=",

self/test/genlex.py modified +1 -1

@@ -22,7 +22,7 @@
2222 "tab": "\t\tx := @;\n", "multi": "x := \"\u00e9\u00e9\u00e9\" + @;\n", "ident64": "x" * 64 + ";\n", "ident63": "x" * 63 + ";\n",
2323 "bigstr": "x := \"" + "a" * 70000 + "\";\n", "empty": "", "nonl": "x := y",
2424 "ops": "+ - * / = # < <= > >= := : ; , . .. ... ( ) [ ] { } ^ & ~ | _ __ _a\n",
25- "words": "and begin break by code const defer div do else elsif end extern for forward if import in link match mod module not of or packed proc record repeat return set shl shr then to type until var variant VOLATILE while xor Volatile\n",
25+ "words": "and begin break by code const defer div do else elsif end extern for forward if import in link match mod module not of or packed proc record repeat return set shl shr then to try type until var variant VOLATILE while xor Volatile\n",
2626 }
2727 for k, v in cases.items():
2828 open(f"{d}/{k}.raz", "wb").write(v.encode("utf-8", "surrogateescape") if isinstance(v, str) else v)

site/build.py modified +1 -1

@@ -48,7 +48,7 @@
4848
4949 KEYWORDS = set("""and begin break by code const defer div do else elsif end
5050 extern for forward if import in link match mod module not of or packed proc
51-record repeat return set shl shr then to type until var variant VOLATILE
51+record repeat return set shl shr then to try type until var variant VOLATILE
5252 while xor""".split())
5353 PREDECLARED = set("""INT UINT I8 I16 I32 I64 U8 U16 U32 U64 F32 F64 BOOL ERROR
5454 true false nil LEN ADR NEW SIZE INC DEC MSG XADD CAS XCHG""".split())

site/content/tour/10-errors.txt (history) modified +10 -8

@@ -53,7 +53,14 @@
5353
5454 ## Passing errors up
5555
56-When a procedure can't do anything useful with an error, it returns it, so the first caller that can decide gets it. There is no hidden unwinding: the `return` is right there.
56+When a procedure can't do anything useful with an error, it returns it, so the first caller that can decide gets it. Written out, that is a test and a `return` after each call:
57+
58+```raz
59+x, err := value(a);
60+if err # nil then return 0, err; end;
61+```
62+
63+`try` says the same in a word. `x := try value(a)` calls `value` and, if the error it returned isn't `nil`, returns that error from the procedure it stands in, with zero for that procedure's other results; otherwise it is `value`'s number. There is no hidden unwinding and no handler: `try` is a `return`, written where the call is, and a procedure that uses it must end in an `ERROR` itself, so its signature says it can fail. `main` returns none, so it tests its errors and deals with them.
5764
5865 ```raz Layers run
5966 module Layers;
@@ -71,15 +78,10 @@
7178 return INT(n), nil;
7279 end;
7380
74-(* the sum of the values of two lines *)
81+(* the sum of the values of two lines: the first error ends it *)
7582 proc sum(a, b: []U8): (INT, ERROR);
76-var x, y: INT; err: ERROR;
7783 begin
78- x, err := value(a);
79- if err # nil then return 0, err; end; (* passed up *)
80- y, err := value(b);
81- if err # nil then return 0, err; end;
82- return x + y, nil;
84+ return try value(a) + try value(b), nil;
8385 end;
8486
8587 proc main*;

site/public/advanced/static.html (history) modified +4 -4

@@ -65,7 +65,7 @@
6565 <span class="cmd">$ ldd Bare</span>
6666 not a dynamic executable
6767 <span class="cmd">$ ls -l Bare | awk &#x27;{print $5, &quot;bytes&quot;}&#x27;</span>
68-26176 bytes</code></pre>
68+26184 bytes</code></pre>
6969 <p>It is statically linked: no interpreter, no shared libraries, no <code>libc</code>. <code>ldd</code> says so.</p>
7070 <h2>What it does when it runs</h2>
7171 <p><code>strace</code> lists every system call a program makes. This is the whole of it:</p>
@@ -134,14 +134,14 @@
134134 <pre class="output term"><code><span class="cmd">$ raz Lean.raz</span>
135135 <span class="cmd">$ raz Heavy.raz</span>
136136 <span class="cmd">$ ls -l Lean Heavy | awk &#x27;{print $9, $5}&#x27;</span>
137-Heavy 28384
138-Lean 28376</code></pre>
137+Heavy 28392
138+Lean 28384</code></pre>
139139 <p>The sizes differ by a few bytes, not by the hundreds of kilobytes that the table and the procedure would take: they are not in the executable at all. You can link in a library module without worrying what else it offers.</p>
140140 <h2>Stripping</h2>
141141 <p><code>-s</code> leaves out what is there for finding faults: the symbols and line numbers, the places a failure is told by, and the profiler. It is for the final build of a size-conscious program; the default keeps them so that gdb and failure messages work.</p>
142142 <pre class="output term"><code><span class="cmd">$ raz -s -o Lean-stripped Lean.raz</span>
143143 <span class="cmd">$ ls -l Lean Lean-stripped | awk &#x27;{print $9, $5}&#x27;</span>
144-Lean 28376
144+Lean 28384
145145 Lean-stripped 6720
146146 <span class="cmd">$ ./Lean-stripped</span>
147147 same program</code></pre>

site/public/spec.html (history) modified +50 -11

@@ -36,7 +36,7 @@
3636 </ul>
3737 <p>raz is a small systems language, first made for x86-64 Linux. A raz program can lay a record over a device’s registers, read and write a device’s memory exactly as written, take part in lock-free algorithms, make system calls and call C libraries. It has no garbage collector and no hidden run time: what the program does is what its text says.</p>
3838 <p>This report defines the language. It is short on purpose. Whatever it doesn’t allow, raz doesn’t have.</p>
39-<p>This is version 2026-10.19 of the report; section 12 says what each version changed. 2026-10.11 and 2026-10.12 are a thaw the owner chose, for a language anyone can build again. They break programs written for 2026-10.10 and before: for 2026-10.9, say, the report of compiler 0.5.0, the last release before them; and 2026-10.12 breaks code procedures written for 2026-10.11.</p>
39+<p>This is version 2026-10.20 of the report; section 12 says what each version changed. 2026-10.11 and 2026-10.12 are a thaw the owner chose, for a language anyone can build again. They break programs written for 2026-10.10 and before: for 2026-10.9, say, the report of compiler 0.5.0, the last release before them; and 2026-10.12 breaks code procedures written for 2026-10.11. 2026-10.20 is a third, for <code>try</code> (section 7.8); it breaks a program that has a name <code>try</code>.</p>
4040 <p>The language is frozen, softly, from this version on: it changes only to mend a defect, and its library grows only by what breaks no program written for it. What anyone wishes it had waits on a list, for a later thaw.</p>
4141 <h1 id="a-first-look">1. A first look</h1>
4242 <pre><code>module Hello;
@@ -55,8 +55,8 @@
5555 <p><strong>Reserved words</strong> are lowercase, except <code>VOLATILE</code>:</p>
5656 <pre><code>and begin break by code const defer div do else elsif end extern for
5757 forward if import in link match mod module not of or packed proc record
58-repeat return set shl shr then to type until var variant VOLATILE while
59-xor</code></pre>
58+repeat return set shl shr then to try type until var variant VOLATILE
59+while xor</code></pre>
6060 <p><code>static</code>, in <code>link static;</code> (section 3), isn’t one.</p>
6161 <p><strong>Predeclared names</strong> are the basic types (section 5.1), <code>ERROR</code>, <code>true</code>, <code>false</code>, <code>nil</code> and the built-in procedures (section 6.8). They belong to a scope around every module, so a module or a procedure may declare the same name for something else, which hides them there.</p>
6262 <p><strong>Numbers.</strong> <code>123</code> is decimal. <code>0FFH</code> is hexadecimal: it starts with a digit, its digits are <code>0</code> to <code>9</code> and <code>A</code> to <code>F</code>, and it ends in <code>H</code>, all in capitals. <code>1.5</code> and <code>2.0E-3</code> are reals; a real always has a digit on both sides of its point, and its exponent, if it has one, is <code>E</code>, a sign if wanted, and digits. A decimal number above the largest <code>I64</code>, or a hexadecimal one above the largest <code>U64</code>, is an error.</p>
@@ -229,6 +229,7 @@
229229 <p><code>set of E</code>, for an enumeration <code>E</code> of at most 64 names, holds any choice of <code>E</code>’s names: bit <code>i</code> stands for the name at position <code>i</code>. It takes the smallest of 1, 2, 4 and 8 bytes that has a bit for each name, so a set can stand for a C flags word.</p>
230230 <h2 id="errors">5.8 Errors</h2>
231231 <pre><code>const NotFound*: ERROR = &quot;not found&quot;;</code></pre>
232+<p>An <code>ERROR</code> is how a procedure says it failed: by convention the last of its results, and <code>nil</code> when nothing failed. A caller that can’t deal with a failure itself passes it on with <code>try</code> (section 7.8).</p>
232233 <p><code>ERROR</code> is a basic type as big as an address. A value of it is made only by a constant declared as above, and each such declaration makes an error different from every other, whatever its message: two modules that both declare <code>"not found"</code> have two different errors. A generic module makes its errors once per instance. <code>nil</code> is no error.</p>
233234 <p>Errors compare with <code>=</code> and <code>#</code> only, by which declaration made them, never by their message. <code>MSG(e)</code> is the message, a <code>[]U8</code>; <code>MSG(nil)</code> is <code>""</code>.</p>
234235 <pre><code>proc find*(key: I64): (^Node, ERROR);
@@ -266,14 +267,15 @@
266267 | &quot;not&quot; Factor | &quot;~&quot; Factor
267268 | &quot;[&quot; [ Expr { &quot;,&quot; Expr } ] &quot;]&quot;
268269 | &quot;{&quot; [ Element { &quot;,&quot; Element } ] &quot;}&quot;
269- | &quot;^&quot; [ &quot;VOLATILE&quot; ] Type &quot;(&quot; Expr &quot;)&quot; .
270+ | &quot;^&quot; [ &quot;VOLATILE&quot; ] Type &quot;(&quot; Expr &quot;)&quot;
271+ | &quot;try&quot; Designator .
270272 Element = Expr | ident &quot;:&quot; Expr .
271273 Designator = QualIdent { Selector } .
272274 Selector = &quot;.&quot; ident | &quot;^&quot; | &quot;[&quot; Expr [ &quot;..&quot; Expr ] &quot;]&quot;
273275 | &quot;(&quot; [ Expr { &quot;,&quot; Expr } ] &quot;)&quot; .</code></pre>
274-<p>The operators bind in the order of the grammar: <code>not</code> and <code>~</code> most tightly, then the multiplying operators, then the adding ones, then the relations, then <code>and</code>, then <code>or</code>. So <code>a + b * c = d</code> is <code>(a + (b * c)) = d</code>, <code>x &amp; 0FH = 0</code> is <code>(x &amp; 0FH) = 0</code>, and <code>i &lt; n and a[i] # 0 or done</code> is <code>((i &lt; n) and (a[i] # 0)) or done</code>. A unary minus applies to the first term: <code>-a * b</code> is <code>-(a * b)</code>.</p>
276+<p>The operators bind in the order of the grammar: <code>not</code>, <code>~</code> and <code>try</code> (section 7.8) most tightly, then the multiplying operators, then the adding ones, then the relations, then <code>and</code>, then <code>or</code>. So <code>a + b * c = d</code> is <code>(a + (b * c)) = d</code>, <code>x &amp; 0FH = 0</code> is <code>(x &amp; 0FH) = 0</code>, and <code>i &lt; n and a[i] # 0 or done</code> is <code>((i &lt; n) and (a[i] # 0)) or done</code>. A unary minus applies to the first term: <code>-a * b</code> is <code>-(a * b)</code>.</p>
275277 <p><code>and</code>, <code>or</code> and <code>not</code> are for <code>BOOL</code>s only; <code>&amp;</code>, <code>|</code>, <code>xor</code> and <code>~</code> are for integers only.</p>
276-<p>A pointer to a record isn’t the record: its fields are <code>p^.f</code>, never <code>p.f</code>, and the elements of a pointer to an array are <code>p^[i]</code>. A statement starts with a name, so <code>^T(x)^ := v</code> isn’t one.</p>
278+<p>A pointer to a record isn’t the record: its fields are <code>p^.f</code>, never <code>p.f</code>, and the elements of a pointer to an array are <code>p^[i]</code>. A statement starts with a name or <code>try</code>, so <code>^T(x)^ := v</code> isn’t one.</p>
277279 <h2 id="integers">6.1 Integers</h2>
278280 <p>Both operands of <code>+ - * div mod &amp; | xor</code>, and of a relation, have the same integer type, or one is an untyped constant that takes the other’s type, which it must fit. So do <code>v</code> and <code>k</code> in <code>INC(v, k)</code> and <code>DEC(v, k)</code>. The result has that type and wraps around at its width: in <code>U8</code>, <code>200 + 100</code> is <code>44</code>. A unary minus wraps too: for <code>x</code> of an unsigned type, <code>-x</code> is <code>0 - x</code>. Two integer types are never mixed, whatever their sizes: with <code>i: I64</code>, <code>i &lt; LEN(s)</code> is an error, and <code>i</code> should be an <code>INT</code>.</p>
279281 <p>Where the report asks for an integer and names no type, as an index, a slice’s bound, a shift’s count, a pointer’s offset <code>i</code> in <code>p + i</code>, or a conversion’s operand, any integer type will do, and its value is taken. On a target whose <code>INT</code> is narrower, a pointer’s offset is cut to an <code>INT</code>.</p>
@@ -467,7 +469,8 @@
467469 | &quot;match&quot; Expr &quot;of&quot; { &quot;|&quot; Arm } &quot;end&quot;
468470 | &quot;return&quot; [ Expr { &quot;,&quot; Expr } ]
469471 | &quot;break&quot;
470- | &quot;defer&quot; Statement .
472+ | &quot;defer&quot; Statement
473+ | &quot;try&quot; Designator .
471474 Arm = ( ident [ &quot;(&quot; ident { &quot;,&quot; ident } &quot;)&quot; ]
472475 | Label { &quot;,&quot; Label } | &quot;else&quot; ) &quot;:&quot; Statements .
473476 Label = Expr [ &quot;..&quot; Expr ] .
@@ -534,7 +537,40 @@
534537 end;
535538
536539 end Head.</code></pre>
537-<p><code>return e;</code> evaluates <code>e</code> before the deferred statements run. A deferred statement can’t contain <code>return</code>, <code>break</code> or <code>defer</code> that would leave it. A failed check, <code>Rt.exit</code> and <code>Sys.exit</code> end the program without running the deferred statements still pending.</p>
540+<p><code>return e;</code> evaluates <code>e</code> before the deferred statements run. A deferred statement can’t contain <code>return</code>, <code>break</code>, <code>defer</code> or <code>try</code> that would leave it. A failed check, <code>Rt.exit</code> and <code>Sys.exit</code> end the program without running the deferred statements still pending.</p>
541+<h2 id="try">7.8 Try</h2>
542+<p>A procedure that can fail returns an <code>ERROR</code> as its last result (section 5.8), <code>nil</code> when it didn’t. A caller that can’t deal with the failure passes it on to its own caller, which <code>try</code> does in a word:</p>
543+<pre><code>proc total(words: [][]U8): (INT, ERROR);
544+var i, sum: INT;
545+begin
546+ for i := 0 to LEN(words) - 1 do
547+ sum := sum + try number(words[i]);
548+ end;
549+ return sum, nil;
550+end;</code></pre>
551+<p><code>try c</code>, where <code>c</code> is a call (below) of a procedure whose last result is an <code>ERROR</code>, makes the call and looks at that error. If it is <code>nil</code>, the program goes on, and <code>try c</code> is what <code>c</code> returned without the error. If it isn’t, the procedure <code>try</code> stands in returns at once, as <code>return</code> does (section 7.3): its last result is that error, and every other result is zero, as a variable of its type starts (section 4). Nothing more of the statement <code>try</code> stands in is done; in the example, <code>sum</code> isn’t assigned. So</p>
552+<pre><code>x := try f(a);</code></pre>
553+<p>is, with <code>e</code> a variable the program can’t name, and <code>0</code> standing for a zero of each of the procedure’s other results:</p>
554+<pre><code>x, e := f(a);
555+if e # nil then return 0, e; end;</code></pre>
556+<p>The error is the one <code>c</code> returned, and compares with <code>=</code> as it did there. <code>try</code> has no handler and keeps no state: it is a <code>return</code>, written where the call is, so that every place a procedure can leave is in its text. A program that means to deal with an error tests it, as section 5.8 shows.</p>
557+<p><strong>What <code>try</code> is applied to.</strong> <code>c</code> is a designator that ends in a call: <code>f(x)</code>, <code>Mod.f(x)</code>, <code>p^.next(x)</code>, or a call through a variable of procedure type. Where the procedure has no parameters its parentheses may be left out, as in a statement (section 7.1), and <code>try</code> calls it: <code>try setup;</code>. A conversion, a built-in procedure (section 6.8) and the case of a variant are written like calls and aren’t procedures’; <code>try</code> can’t be applied to them.</p>
558+<p><strong>What <code>try c</code> is.</strong> <code>c</code>’s results but the last.</p>
559+<ul>
560+<li>With none, <code>try c</code> isn’t a value and stands only as a statement: <code>try flush;</code>.</li>
561+<li>With one, it is a value of that type, an operand wherever <code>c</code> would be: <code>n := try number(s);</code>, <code>sum + try number(s)</code>, <code>if try ready(fd) then</code>. Like <code>not</code>, it applies to the factor after it: <code>try f(x) + 1</code> is <code>(try f(x)) + 1</code>.</li>
562+<li>With several, it stands only on the right of a multiple assignment, as <code>c</code> itself would, with a target for each: <code>a, b := try f(x);</code>.</li>
563+</ul>
564+<p>As a statement, <code>try c;</code> drops the values of <code>c</code> that it has, and a dropped value is warned of as a call that drops a result is (section 10); <code>_ := try c;</code> and <code>a, _ := try c;</code> say it is meant (section 7.1). The error is never dropped: <code>try</code> is the way of passing it on.</p>
565+<p><strong>Where <code>try</code> may stand.</strong> Every use of <code>try</code> is an error unless:</p>
566+<ul>
567+<li>the procedure it stands in has an <code>ERROR</code> as its last result. A module’s body, and a procedure with no results, such as <code>proc main*;</code>, have none: there an error is dealt with where it is found, by a test;</li>
568+<li>the last result of the procedure <code>c</code> calls is an <code>ERROR</code>;</li>
569+<li>it is not inside a deferred statement, which <code>try</code> would leave (section 7.7).</li>
570+</ul>
571+<p>A generic module is checked in each instance (section 3), so a procedure of an instance whose last result, by its type arguments, is no <code>ERROR</code> and uses <code>try</code> is an error in that instance.</p>
572+<p><strong>Order.</strong> The arguments of <code>c</code> are evaluated from left to right, then <code>c</code> is called, and then its error is looked at (section 7.5). The designators on the left of an assignment are evaluated before its right side as always, so in <code>a[i()] := try g()</code>, <code>i</code> is called, then <code>g</code>; if <code>g</code> fails, nothing is assigned. A <code>try</code> in the right operand of <code>and</code> or <code>or</code> is reached only when that operand is evaluated (section 6.2).</p>
573+<p><strong>Deferred statements.</strong> When <code>try</code> returns, the statements deferred in the procedure and not yet run are run, the last first, as for a <code>return</code> (section 7.7), after the error and the zero results have been chosen; no deferred statement can change them.</p>
538574 <h1 id="procedures">8. Procedures</h1>
539575 <pre><code>ProcDeclaration = &quot;proc&quot; IdentDef Signature &quot;;&quot;
540576 ( &quot;forward&quot; | { LocalDeclaration } &quot;begin&quot; Statements &quot;end&quot; [ ident ]
@@ -548,7 +584,7 @@
548584 Results = Type | &quot;(&quot; Type { &quot;,&quot; Type } &quot;)&quot; .</code></pre>
549585 <p>A procedure without parameters may leave out the parentheses, both where it is declared (<code>proc main*;</code>) and where it is called (<code>Out.ln</code>). Used without parentheses in an expression, a procedure is a procedure value, not a call.</p>
550586 <p><strong>Parameters.</strong> A value parameter is a copy: the procedure may change it, and the caller’s variable stays as it was. A <code>var</code> parameter is the caller’s variable itself; its argument must be a variable of exactly the parameter’s type.</p>
551-<p><strong>Results.</strong> A procedure returns nothing, one value, or several. A call that returns several values can only stand on the right of a multiple assignment, alone as a statement, or alone after <code>return</code> in a procedure whose results are of the same types, in the same order, which then returns them as they are: <code>return divmod(n, 2);</code>.</p>
587+<p><strong>Results.</strong> A procedure returns nothing, one value, or several. A call that returns several values can only stand on the right of a multiple assignment, alone as a statement, or alone after <code>return</code> in a procedure whose results are of the same types, in the same order, which then returns them as they are: <code>return divmod(n, 2);</code>. A procedure that can fail has an <code>ERROR</code> as its last result (section 5.8), which <code>try</code> passes on (section 7.8).</p>
552588 <pre><code>module Divide;
553589 import Out;
554590
@@ -1059,6 +1095,7 @@
10591095 <li><strong>2026-10.17.</strong> <code>COPY</code> copies the elements of one array or slice to another as a block (section 6.8).</li>
10601096 <li><strong>2026-10.18.</strong> A code procedure takes and returns slices (section 8).</li>
10611097 <li><strong>2026-10.19.</strong> The library gains <code>Bytes</code> (section 11).</li>
1098+<li><strong>2026-10.20.</strong> <code>try</code>: a call of a procedure whose last result is an <code>ERROR</code>, which makes the procedure it stands in return that error when it isn’t <code>nil</code> (sections 2, 5.8, 6, 7.8 and appendix B). <code>try</code> becomes a reserved word, which breaks a program with a name <code>try</code>.</li>
10621099 </ul>
10631100 <h1 id="appendix-a.-what-an-implementation-chooses">Appendix A. What an implementation chooses</h1>
10641101 <p>Everything in this report binds every implementation of raz, except what follows, which each chooses for itself and documents. This compiler’s choices are in <code>doc/compiler.md</code>, under “This compiler’s choices”. The programs in <code>conform/</code> are how an implementation shows that it follows this report: it passes them all, its reals aside where its target has none; <code>conform/check.sh</code> runs them.</p>
@@ -1133,7 +1170,8 @@
11331170 | &quot;not&quot; Factor | &quot;~&quot; Factor
11341171 | &quot;[&quot; [ Expr { &quot;,&quot; Expr } ] &quot;]&quot;
11351172 | &quot;{&quot; [ Element { &quot;,&quot; Element } ] &quot;}&quot;
1136- | &quot;^&quot; [ &quot;VOLATILE&quot; ] Type &quot;(&quot; Expr &quot;)&quot; .
1173+ | &quot;^&quot; [ &quot;VOLATILE&quot; ] Type &quot;(&quot; Expr &quot;)&quot;
1174+ | &quot;try&quot; Designator .
11371175 Element = Expr | ident &quot;:&quot; Expr .
11381176 Designator = QualIdent { Selector } .
11391177 Selector = &quot;.&quot; ident | &quot;^&quot; | &quot;[&quot; Expr [ &quot;..&quot; Expr ] &quot;]&quot;
@@ -1151,7 +1189,8 @@
11511189 | &quot;match&quot; Expr &quot;of&quot; { &quot;|&quot; Arm } &quot;end&quot;
11521190 | &quot;return&quot; [ Expr { &quot;,&quot; Expr } ]
11531191 | &quot;break&quot;
1154- | &quot;defer&quot; Statement .
1192+ | &quot;defer&quot; Statement
1193+ | &quot;try&quot; Designator .
11551194 Arm = ( ident [ &quot;(&quot; ident { &quot;,&quot; ident } &quot;)&quot; ]
11561195 | Label { &quot;,&quot; Label } | &quot;else&quot; ) &quot;:&quot; Statements .
11571196 Label = Expr [ &quot;..&quot; Expr ] .

site/public/tour/errors.html (history) modified +21 -8

@@ -56,6 +56,16 @@
5656 <span class="kw">return</span> <span class="ty">INT</span>(n), <span class="ty">nil</span>;
5757 <span class="kw">end</span>;
5858
59+<span class="comment">(* the sum of the numbers in words: the first error ends it *)</span>
60+<span class="kw">proc</span> total(words: [][]<span class="ty">U8</span>): (<span class="ty">INT</span>, <span class="ty">ERROR</span>);
61+<span class="kw">var</span> i, sum: <span class="ty">INT</span>;
62+<span class="kw">begin</span>
63+ <span class="kw">for</span> i := <span class="number">0</span> <span class="kw">to</span> <span class="ty">LEN</span>(words) - <span class="number">1</span> <span class="kw">do</span>
64+ sum := sum + <span class="kw">try</span> number(words[i]);
65+ <span class="kw">end</span>;
66+ <span class="kw">return</span> sum, <span class="ty">nil</span>;
67+<span class="kw">end</span>;
68+
5969 <span class="kw">proc</span> main*;
6070 <span class="kw">var</span> words: [<span class="number">3</span>][]<span class="ty">U8</span>; i, n: <span class="ty">INT</span>; err: <span class="ty">ERROR</span>;
6171 <span class="kw">begin</span>
@@ -68,12 +78,18 @@
6878 <span class="kw">end</span>;
6979 Out.ln;
7080 <span class="kw">end</span>;
81+ n, err := total([<span class="string">&quot;1&quot;</span>, <span class="string">&quot;2&quot;</span>, <span class="string">&quot;3&quot;</span>]);
82+ Out.int(n); Out.ln;
83+ n, err := total(words);
84+ <span class="kw">if</span> err # <span class="ty">nil</span> <span class="kw">then</span> Out.str(<span class="ty">MSG</span>(err)); Out.ln; <span class="kw">end</span>;
7185 <span class="kw">end</span>;
7286
7387 <span class="kw">end</span> Errors.</code></pre>
7488 <pre class="output"><code>42
7589 empty
7690 not a number up to 1000
91+6
92+nothing to read
7793 </code></pre>
7894 <p>A procedure that can fail returns an <code>ERROR</code> beside its result, and <code>nil</code> when it didn't. Each <code>ERROR</code> constant is an error of its own, compared with <code>=</code> by which declaration made it, never by its message; <code>MSG(err)</code> is the message. An exported one, as <code>Empty</code> is here, lets the callers tell it from the others. raz has no exceptions, so every failure is visible in the signature and handled where the call is written.</p>
7995 <h2>Handling them by kind</h2>
@@ -121,7 +137,9 @@
121137 error: out of range
122138 </code></pre>
123139 <h2>Passing errors up</h2>
124-<p>When a procedure can't do anything useful with an error, it returns it, so the first caller that can decide gets it. There is no hidden unwinding: the <code>return</code> is right there.</p>
140+<p>When a procedure can't do anything useful with an error, it returns it, so the first caller that can decide gets it. Written out, that is a test and a <code>return</code> after each call:</p>
141+<p>``<code>raz x, err := value(a); if err # nil then return 0, err; end; </code>``</p>
142+<p><code>try</code> says the same in a word. <code>x := try value(a)</code> calls <code>value</code> and, if the error it returned isn't <code>nil</code>, returns that error from the procedure it stands in, with zero for that procedure's other results; otherwise it is <code>value</code>'s number. There is no hidden unwinding and no handler: <code>try</code> is a <code>return</code>, written where the call is, and a procedure that uses it must end in an <code>ERROR</code> itself, so its signature says it can fail. <code>main</code> returns none, so it tests its errors and deals with them.</p>
125143 <div class="file"><span>Layers.raz</span></div><pre class="code"><code><span class="kw">module</span> Layers;
126144 <span class="kw">import</span> Out, Str;
127145
@@ -137,15 +155,10 @@
137155 <span class="kw">return</span> <span class="ty">INT</span>(n), <span class="ty">nil</span>;
138156 <span class="kw">end</span>;
139157
140-<span class="comment">(* the sum of the values of two lines *)</span>
158+<span class="comment">(* the sum of the values of two lines: the first error ends it *)</span>
141159 <span class="kw">proc</span> sum(a, b: []<span class="ty">U8</span>): (<span class="ty">INT</span>, <span class="ty">ERROR</span>);
142-<span class="kw">var</span> x, y: <span class="ty">INT</span>; err: <span class="ty">ERROR</span>;
143160 <span class="kw">begin</span>
144- x, err := value(a);
145- <span class="kw">if</span> err # <span class="ty">nil</span> <span class="kw">then</span> <span class="kw">return</span> <span class="number">0</span>, err; <span class="kw">end</span>; <span class="comment">(* passed up *)</span>
146- y, err := value(b);
147- <span class="kw">if</span> err # <span class="ty">nil</span> <span class="kw">then</span> <span class="kw">return</span> <span class="number">0</span>, err; <span class="kw">end</span>;
148- <span class="kw">return</span> x + y, <span class="ty">nil</span>;
161+ <span class="kw">return</span> <span class="kw">try</span> value(a) + <span class="kw">try</span> value(b), <span class="ty">nil</span>;
149162 <span class="kw">end</span>;
150163
151164 <span class="kw">proc</span> main*;

site/public/tour/hello.html (history) modified +1 -1

@@ -70,7 +70,7 @@
7070 <span class="cmd">$ raz run Quiet.raz</span>
7171 hello, again
7272 <span class="cmd">$ ls -l Quiet | awk &#x27;{print $5, &quot;bytes&quot;}&#x27;</span>
73-28384 bytes</code></pre>
73+28392 bytes</code></pre>
7474 <p>The program is a static executable with no run time besides the code it uses, so it is a few kilobytes, and runs without any library installed.</p>
7575 <h2>What <code>Out</code> can write</h2>
7676 <p><code>Out</code> is the library's buffered output. It writes strings, single characters, numbers in decimal or hexadecimal, and a line feed. A string is written as it is, with <code>\n</code> for a line feed, <code>\t</code> for a tab, <code>\"</code> and <code>\\</code>.</p>

src/gen.pas modified +37 -0

@@ -206,6 +206,8 @@
206206 procedure ResultTo(off: int64; size: longint);
207207 procedure CopyResult(off, size: int64);
208208 procedure ReturnJump;
209+procedure TryAlign;
210+procedure TryReturn(slot: int64);
209211 procedure EndProc(c: longint; open: boolean);
210212 function DeferBegin(var L, saved: longint): longint;
211213 procedure DeferEnd(L, saved: longint);
@@ -2062,6 +2064,41 @@
20622064 if resType^.form = fReal then begin XValueTo(depth - 1, 0); Drop end
20632065 else PopTo(RAX);
20642066 end;
2067+ Jmp(exitL);
2068+end;
2069+
2070+{ The first of what try does where the error isn't nil (the report, 7.8):
2071+ the machine's stack made even, as the deferred statements about to be
2072+ run expect to find it. try can stand among the arguments of another
2073+ call, where quadwords have been pushed. Nothing is lost: the frame is
2074+ above rsp, and the code returns through the frame pointer. }
2075+procedure TryAlign;
2076+begin
2077+ AluI(aluAnd, RSP, -16);
2078+end;
2079+
2080+{ The rest of it: the procedure returns the error in the frame slot, and
2081+ a zero for each of its other results. Only code is made: no entry of
2082+ the stack of values is touched, since the code that follows is the
2083+ code for an error that is nil, with the stack as it was. }
2084+procedure TryReturn(slot: int64);
2085+var f: PObj;
2086+begin
2087+ if BehindPointer(resType) then begin
2088+ Load(RDI, Mem(RBP, retSlot), 8, false);
2089+ MovRI(RCX, resType^.size);
2090+ MovRI(RAX, 0);
2091+ RepStosb;
2092+ f := resType^.fields;
2093+ while f^.next <> nil do f := f^.next;
2094+ Load(RCX, Mem(RBP, slot), 8, false);
2095+ Load(RDX, Mem(RBP, retSlot), 8, false);
2096+ Store(Mem(RDX, f^.val), RCX, 8);
2097+ Load(RAX, Mem(RBP, retSlot), 8, false);
2098+ end else if InTwoRegs(resType) then begin
2099+ Load(RDX, Mem(RBP, slot), 8, false);
2100+ MovRI(RAX, 0);
2101+ end else Load(RAX, Mem(RBP, slot), 8, false);
20652102 Jmp(exitL);
20662103 end;
20672104

src/parse.pas modified +104 -1

@@ -1074,6 +1074,91 @@
10741074 end;
10751075 end;
10761076
1077+procedure RunDefers(base: longint); forward;
1078+
1079+{ The type of the last result of t, the results of a procedure: t if
1080+ it has one, else the last of its several. }
1081+function LastResult(t: PType): PType;
1082+var f: PObj;
1083+begin
1084+ if not t^.tuple then exit(t);
1085+ f := t^.fields;
1086+ while f^.next <> nil do f := f^.next;
1087+ LastResult := f^.typ;
1088+end;
1089+
1090+{ The results of the tuple t but the last: the same fields, one fewer }
1091+function WithoutLast(t: PType): PType;
1092+var r: PType;
1093+begin
1094+ r := NewType(fRecord, t^.size, t^.align);
1095+ r^.tuple := true;
1096+ r^.fields := t^.fields;
1097+ r^.len := t^.len - 1;
1098+ WithoutLast := r;
1099+end;
1100+
1101+{ try c (the report, 7.8): the call c, then the error it returned, its
1102+ last result: if that isn't nil, the procedure returns it, and a zero
1103+ for each of its other results, after running the deferred statements
1104+ in force. x is left c's other results: none (mNone), one (a value) or
1105+ several (a tuple, for a multiple assignment). The error is kept in a
1106+ slot of the frame, and tested there; the code for it, out of line,
1107+ is made with the stack of values as it stands, and leaves it so,
1108+ since what follows is the code for an error that is nil. }
1109+procedure TryCall(var x: TItem);
1110+var
1111+ called: boolean; c: TCall; start, at: TPos; res: PType; last: PObj; slot: int64; ok: longint;
1112+begin
1113+ start := TokPos;
1114+ Next;
1115+ if deferring then MarkAt(SpanFrom(start), 'try can''t leave a deferred statement');
1116+ if curResult = nil then
1117+ MarkAt(SpanFrom(start), 'try needs a procedure that ends in an ERROR result, and this returns nothing')
1118+ else if LastResult(curResult) <> tError then
1119+ MarkAt(SpanFrom(start), 'try needs a procedure that ends in an ERROR result, and this returns ' + TypeName(curResult));
1120+ Designator(x, called);
1121+ if not called and ((x.mode = mProc) or ((x.mode in [mVar, mStack]) and (x.typ^.form = fProc))) then begin
1122+ { a procedure without parameters, written without parentheses }
1123+ at := x.pos;
1124+ BeginCall(c, x);
1125+ EndCall(c, x);
1126+ x.pos := at;
1127+ called := true;
1128+ end;
1129+ if not called then MarkAt(x.pos, 'try needs a call, found ' + What(x));
1130+ if x.mode = mNone then
1131+ MarkAt(x.pos, 'try needs a call that returns an ERROR last, and this returns nothing');
1132+ if LastResult(x.typ) <> tError then
1133+ MarkAt(x.pos, 'try needs a call that returns an ERROR last, and this returns ' + TypeName(x.typ));
1134+ res := x.typ;
1135+ if x.mode = mStack then begin
1136+ { an ERROR alone }
1137+ slot := AllocTemp(8, 8);
1138+ PopVar(FrameAdr(slot), 8);
1139+ x.mode := mNone; x.typ := tNone;
1140+ end else if x.mode = mWords then begin
1141+ { two words, the error on top }
1142+ slot := AllocTemp(8, 8);
1143+ PopVar(FrameAdr(slot), 8);
1144+ x.mode := mStack; x.typ := res^.fields^.typ;
1145+ end else begin
1146+ { several, in a temporary: the error is where it is }
1147+ last := res^.fields;
1148+ while last^.next <> nil do last := last^.next;
1149+ slot := x.off + last^.val;
1150+ if res^.len = 2 then Field(x, res^.fields) else x.typ := WithoutLast(res);
1151+ end;
1152+ ok := NoLabel;
1153+ PushVar(FrameAdr(slot), 8, false, kWord);
1154+ JumpIf(ok, false);
1155+ if numDefers > 0 then TryAlign;
1156+ RunDefers(0);
1157+ TryReturn(slot);
1158+ Fix(ok);
1159+ x.pos := SpanFrom(start);
1160+end;
1161+
10771162 procedure Factor(var x: TItem; want: PType);
10781163 var called, vol, several: boolean; t: PType; start: TPos; s: shortstring;
10791164 begin
@@ -1101,6 +1186,12 @@
11011186 end;
11021187 end;
11031188 sLparen: begin Next; Expression(x, want); Expect(sRparen) end;
1189+ sTry: begin
1190+ TryCall(x);
1191+ if x.mode = mNone then MarkAt(x.pos, 'this try has no value');
1192+ if x.typ^.tuple then
1193+ MarkHelp(x.pos, 'this try has several values', 'they go to variables: a, b := try f(...)');
1194+ end;
11041195 sNot: begin Next; Factor(x, nil); NotOp(x) end;
11051196 sTilde: begin Next; Factor(x, nil); Complement(x) end;
11061197 sLbrak: ArrayLiteral(x, want);
@@ -1610,7 +1701,10 @@
16101701 end;
16111702 until false;
16121703 Expect(sBecomes);
1613- Designator(y, called);
1704+ if tok = sTry then begin
1705+ TryCall(y);
1706+ called := true;
1707+ end else Designator(y, called);
16141708 if not called or not y.typ^.tuple or (y.typ^.len <> n) then begin
16151709 MarkAt(y.pos, 'expected a call with ' + IntStr(n) + ' results');
16161710 if y.mode = mWords then CopyToTemp(y);
@@ -1792,6 +1886,15 @@
17921886 Jump(curLoop^.brk);
17931887 end;
17941888 sDefer: Defer;
1889+ sTry: begin
1890+ TryCall(x);
1891+ if (x.mode <> mNone) and (numDrops <= High(drops)) then begin
1892+ drops[numDrops].at := x.pos;
1893+ if x.typ^.tuple then drops[numDrops].n := x.typ^.len else drops[numDrops].n := 1;
1894+ inc(numDrops);
1895+ end;
1896+ Discard(x);
1897+ end;
17951898 sArrow: MarkHelp(TokPos, 'a statement starts with a name', 'convert into a pointer variable, then assign through that');
17961899 else if AtLineStart then EndMissing(MissingPos, 'expected "end", found ' + Found)
17971900 else Expected('a statement');

src/raz.pas modified +1 -1

@@ -34,7 +34,7 @@
3434 { what git describe says, made by make: 0.3.0 at the tag v0.3.0,
3535 0.3.0-5-g38d29a8 five commits past it }
3636 Version = {$I version.inc};
37- Report = '2026-10.19'; { the version of doc/raz.md it follows }
37+ Report = '2026-10.20'; { the version of doc/raz.md it follows }
3838 MemfdCreate = 319; { the system call; FPC 3.2.2 has no name for it }
3939 MfdCloexec = 1; { an ELF still executes: the kernel opens it first }
4040

src/scan.pas modified +2 -2

@@ -29,7 +29,7 @@
2929 sAnd, sBegin, sBreak, sBy, sCode, sConst, sDefer, sDiv, sDo, sElse,
3030 sElsif, sEnd, sExtern, sFor, sForward, sIf, sImport, sIn, sLink,
3131 sMatch, sMod, sModule, sNot, sOf, sOr, sPacked, sProc, sRecord,
32- sRepeat, sReturn, sSet, sShl, sShr, sThen, sTo, sType, sUntil, sVar,
32+ sRepeat, sReturn, sSet, sShl, sShr, sThen, sTo, sTry, sType, sUntil, sVar,
3333 sVariant, sVolatile, sWhile, sXor,
3434 sEof);
3535
@@ -106,7 +106,7 @@
106106 'else', 'elsif', 'end', 'extern', 'for', 'forward', 'if', 'import',
107107 'in', 'link', 'match', 'mod', 'module', 'not', 'of', 'or', 'packed',
108108 'proc', 'record', 'repeat', 'return', 'set', 'shl', 'shr', 'then',
109- 'to', 'type', 'until', 'var', 'variant', 'VOLATILE', 'while', 'xor');
109+ 'to', 'try', 'type', 'until', 'var', 'variant', 'VOLATILE', 'while', 'xor');
110110 Ops: array[sPlus..sBlank] of string[3] = (
111111 '+', '-', '*', '/', '=', '#', '<', '<=', '>', '>=',
112112 ':=', ':', ';', ',', '.', '..', '...',

test/err/TryDrops.args (history) added +1 -0

@@ -0,0 +1 @@
1+-Werror

test/err/TryDrops.err (history) added +9 -0

@@ -0,0 +1,9 @@
1+test/err/TryDrops.raz:13:5: error: the result of try half is dropped
2+ 13 | try half(4);
3+ | ^^^^^^^^^^^
4+help: if that is meant, write _ := try half(...)
5+test/err/TryDrops.raz:16:5: error: the results of try three are dropped
6+ 16 | try three(4);
7+ | ^^^^^^^^^^^^
8+help: if that is meant, write _, _ := try three(...)
9+raz: 2 errors

test/err/TryDrops.raz (history) added +20 -0

@@ -0,0 +1,20 @@
1+module TryDrops;
2+proc half(n: INT): (INT, ERROR);
3+begin
4+ return n div 2, nil;
5+end;
6+proc three(n: INT): (INT, INT, ERROR);
7+begin
8+ return n, n, nil;
9+end;
10+proc g*: ERROR;
11+var n: INT;
12+begin
13+ try half(4);
14+ _ := try half(4);
15+ n, _ := try three(4);
16+ try three(4);
17+ _ := n;
18+ return nil;
19+end;
20+end TryDrops.

test/msg/TryConversion.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/TryConversion.raz:5:14: error: try needs a call, found INT
2+ 5 | n := try INT(n);
3+ | ^^^^^^
4+raz: 1 error

test/msg/TryCount.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/TryCount.raz:9:13: error: expected a call with 2 results
2+ 9 | a, b := try f();
3+ | ^^^^^^^
4+raz: 1 error

test/msg/TryDeferred.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/TryDeferred.raz:8:11: error: try can't leave a deferred statement
2+ 8 | defer try f();
3+ | ^^^
4+raz: 1 error

test/msg/TryInBody.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/TryInBody.raz:7:5: error: try needs a procedure that ends in an ERROR result, and this returns nothing
2+ 7 | try f();
3+ | ^^^
4+raz: 1 error

test/msg/TryInMain.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/TryInMain.raz:8:5: error: try needs a procedure that ends in an ERROR result, and this returns nothing
2+ 8 | try f();
3+ | ^^^
4+raz: 1 error

test/msg/TryNeedsArguments.err (history) added +7 -0

@@ -0,0 +1,7 @@
1+conform/err/TryNeedsArguments.raz:8:10: error: too few arguments: f takes 1
2+ 8 | try f;
3+ | ^
4+conform/err/TryNeedsArguments.raz:2:6: note: the signature is here
5+ 2 | proc f(n: INT): ERROR;
6+ | ^
7+raz: 1 error

test/msg/TryNoValue.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/TryNoValue.raz:9:10: error: this try has no value
2+ 9 | n := try f();
3+ | ^^^^^^^
4+raz: 1 error

test/msg/TryNotACall.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/TryNotACall.raz:5:9: error: try needs a call, found INT
2+ 5 | try n;
3+ | ^
4+raz: 1 error

test/msg/TryNotError.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/TryNotError.raz:8:9: error: try needs a call that returns an ERROR last, and this returns INT
2+ 8 | try f;
3+ | ^
4+raz: 1 error

test/msg/TryReturnsNothing.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/TryReturnsNothing.raz:7:9: error: try needs a call that returns an ERROR last, and this returns nothing
2+ 7 | try f();
3+ | ^^^
4+raz: 1 error

test/msg/TrySeveralValues.err (history) added +5 -0

@@ -0,0 +1,5 @@
1+conform/err/TrySeveralValues.raz:9:10: error: this try has several values
2+ 9 | n := try f();
3+ | ^^^^^^^
4+help: they go to variables: a, b := try f(...)
5+raz: 1 error

test/msg/TryWrongResults.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+conform/err/TryWrongResults.raz:8:5: error: try needs a procedure that ends in an ERROR result, and this returns (INT, BOOL)
2+ 8 | try f();
3+ | ^^^
4+raz: 1 error

tools/Scan.raz (history) modified +1 -1

@@ -20,7 +20,7 @@
2020 end;
2121
2222 const
23- words = "and begin break by code const defer div do else elsif end extern for forward if import in link match mod module not of or packed proc record repeat return set shl shr then to type until var variant VOLATILE while xor";
23+ words = "and begin break by code const defer div do else elsif end extern for forward if import in link match mod module not of or packed proc record repeat return set shl shr then to try type until var variant VOLATILE while xor";
2424
2525 proc isSpace*(c: U8): BOOL;
2626 begin