raz / commit 57a5dff9

commit
57a5dff9e4efae85c13fc4f5f94aef52f2e08d5f
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
80d65028
Report 2026-10.21: an enumeration's match arm may name several names

Section 7.4 and 12; the parser takes the list, the arms share one place;
conform/ tests the run, a name twice in a list, and a name left out.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

patch · log

12 files changed, +119 -15

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.20, whose `try` returns an error that isn't
105+by the owner's word: report 2026-10.12; the compiler follows 2026-10.21, whose `match` on an enumeration takes
106+several names to an arm (10.21), and 2026-10.20, whose `try` returns an error that isn't
106107 nil from the procedure it stands in (10.20, the owner's word), and 2026-10.19,
107108 whose `Sys` writes without waiting, for rat's pastes (10.13), and
108109 whose blank, `_ := f(x)`, drops a result that is otherwise warned of

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

@@ -0,0 +1,10 @@
1+module MatchEnumListMissing;
2+type Op = (plus, minus, times);
3+proc main*;
4+var op: Op;
5+begin
6+ match op of
7+ | plus, minus:
8+ end;
9+end;
10+end MatchEnumListMissing.

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

@@ -0,0 +1,11 @@
1+module MatchEnumListSame;
2+type Op = (plus, minus, times);
3+proc main*;
4+var op: Op;
5+begin
6+ match op of
7+ | plus, plus:
8+ | minus, times:
9+ end;
10+end;
11+end MatchEnumListSame.

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

@@ -0,0 +1,11 @@
1+module MatchEnumListTwice;
2+type Op = (plus, minus, times);
3+proc main*;
4+var op: Op;
5+begin
6+ match op of
7+ | plus, minus:
8+ | minus, times:
9+ end;
10+end;
11+end MatchEnumListTwice.

conform/run/MatchEnumList.expect (history) added +5 -0

@@ -0,0 +1,5 @@
1+1 10
2+1 10
3+2 20
4+3 10
5+3 20

conform/run/MatchEnumList.raz (history) added +34 -0

@@ -0,0 +1,34 @@
1+module MatchEnumList;
2+import Out;
3+
4+type Op = (plus, minus, times, over, rest);
5+
6+proc kind(op: Op): INT;
7+begin
8+ match op of
9+ | plus, minus: return 1;
10+ | times: return 2;
11+ | over, rest: return 3;
12+ end;
13+end;
14+
15+proc wide(op: Op): INT;
16+var n: INT;
17+begin
18+ n := 0;
19+ match op of
20+ | minus, over, plus: n := 10;
21+ | else: n := 20;
22+ end;
23+ return n;
24+end;
25+
26+proc main*;
27+var op: Op;
28+begin
29+ for op := plus to rest do
30+ Out.int(kind(op)); Out.str(" "); Out.int(wide(op)); Out.ln;
31+ end;
32+end;
33+
34+end MatchEnumList.

doc/raz.md (history) modified +17 -2

@@ -9,7 +9,7 @@
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.20 of the report; section 12 says what each
12+This is version 2026-10.21 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
@@ -902,7 +902,20 @@
902902 `| else:` arm, which must come last.
903903
904904 `match` on an enumeration works the same way: each arm names one of the
905-enumeration's names.
905+enumeration's names, or several, separated by commas, for the arm to
906+run when the value is any of them:
907+
908+```
909+match op of
910+| sPlus, sMinus: kind := additive;
911+| sTimes: kind := multiplicative;
912+| else:
913+end;
914+```
915+
916+Every name must have an arm, and only one, unless there is an `| else:`
917+arm. A variant's arm names one case: the fields it may name belong to
918+that case alone.
906919
907920 `match` on an integer runs the arm whose labels hold its value:
908921
@@ -2041,6 +2054,8 @@
20412054 `ERROR`, which makes the procedure it stands in return that error
20422055 when it isn't `nil` (sections 2, 5.8, 6, 7.8 and appendix B). `try`
20432056 becomes a reserved word, which breaks a program with a name `try`.
2057+- **2026-10.21.** An arm of a `match` on an enumeration may name
2058+ several of its names (section 7.4).
20442059
20452060 ## Appendix A. What an implementation chooses
20462061

src/parse.pas modified +16 -11

@@ -1600,7 +1600,7 @@
16001600
16011601 procedure MatchStatement(const start: TPos; ind: longint);
16021602 var
1603- x: TItem; t: PType; c, f, o: PObj; p: int64; L, endL, n, disp, elseAt: longint;
1603+ x: TItem; t: PType; c, f, o: PObj; p: int64; L, endL, n, first, disp, elseAt: longint;
16041604 seen: array[0..255] of boolean; hasElse, all, byValue: boolean; endAt: TPos; ls: TLabels;
16051605 begin
16061606 Next;
@@ -1633,18 +1633,23 @@
16331633 end else if t^.form = fInt then
16341634 IntArm(t, ls, endL)
16351635 else begin
1636- if tok <> sIdent then Expected('a case');
1637- c := t^.fields;
1638- while (c <> nil) and (c^.name <> id) do c := c^.next;
1639- if c = nil then Mark(NameOf(id) + ' isn''t a case of ' + TypeName(t));
1640- if (c^.val <= High(seen)) and seen[c^.val] then Mark(NameOf(c^.name) + ' has two arms');
1641- if c^.val <= High(seen) then seen[c^.val] := true;
1642- Next;
1636+ first := ls.n;
16431637 L := NoLabel;
1644- if t^.form = fEnum then begin
1638+ repeat
1639+ if tok <> sIdent then Expected('a case');
1640+ c := t^.fields;
1641+ while (c <> nil) and (c^.name <> id) do c := c^.next;
1642+ if c = nil then Mark(NameOf(id) + ' isn''t a case of ' + TypeName(t));
1643+ if (c^.val <= High(seen)) and seen[c^.val] then Mark(NameOf(c^.name) + ' has two arms');
1644+ if c^.val <= High(seen) then seen[c^.val] := true;
1645+ Next;
1646+ if t^.form <> fEnum then begin MatchTag(p, c^.val, L); break end;
1647+ { an enumeration's arm may name several, which share its place }
16451648 ls.lo[ls.n] := c^.val; ls.hi[ls.n] := c^.val;
16461649 inc(ls.n);
1647- end else MatchTag(p, c^.val, L);
1650+ if tok <> sComma then break;
1651+ Next;
1652+ until false;
16481653 OpenScope(NewScope);
16491654 if tok = sLparen then begin
16501655 Next;
@@ -1667,7 +1672,7 @@
16671672 Expect(sRparen);
16681673 end;
16691674 Expect(sColon);
1670- if t^.form = fEnum then ls.at[ls.n - 1] := pc;
1675+ for n := first to ls.n - 1 do ls.at[n] := pc;
16711676 Statements;
16721677 CloseScope;
16731678 Jump(endL);

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.20'; { the version of doc/raz.md it follows }
37+ Report = '2026-10.21'; { 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

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

@@ -0,0 +1,4 @@
1+conform/err/MatchEnumListMissing.raz:8:5: error: no arm for times
2+ 8 | end;
3+ | ^^^
4+raz: 1 error

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

@@ -0,0 +1,4 @@
1+conform/err/MatchEnumListSame.raz:7:13: error: plus has two arms
2+ 7 | | plus, plus:
3+ | ^^^^
4+raz: 1 error

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

@@ -0,0 +1,4 @@
1+conform/err/MatchEnumListTwice.raz:8:7: error: minus has two arms
2+ 8 | | minus, times:
3+ | ^^^^^
4+raz: 1 error