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>
| @@ -102,7 +102,8 @@ | ||
| 102 | 102 | defect, and the library grows only by what breaks no program written |
| 103 | 103 | for it. A wish for more, the owner's or yours, goes on the list in |
| 104 | 104 | `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 | |
| 106 | 107 | nil from the procedure it stands in (10.20, the owner's word), and 2026-10.19, |
| 107 | 108 | whose `Sys` writes without waiting, for rat's pastes (10.13), and |
| 108 | 109 | whose blank, `_ := f(x)`, drops a result that is otherwise warned of |
| @@ -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. |
| @@ -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. |
| @@ -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. |
| @@ -0,0 +1,5 @@ | ||
| 1 | +1 10 | |
| 2 | +1 10 | |
| 3 | +2 20 | |
| 4 | +3 10 | |
| 5 | +3 20 |
| @@ -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. |
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | This report defines the language. It is short on purpose. Whatever it |
| 10 | 10 | doesn't allow, raz doesn't have. |
| 11 | 11 | |
| 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 | |
| 13 | 13 | version changed. 2026-10.11 and 2026-10.12 are a thaw the owner chose, |
| 14 | 14 | for a language anyone can build again. They break programs written |
| 15 | 15 | for 2026-10.10 and before: for 2026-10.9, say, the report of compiler |
| @@ -902,7 +902,20 @@ | ||
| 902 | 902 | `| else:` arm, which must come last. |
| 903 | 903 | |
| 904 | 904 | `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. | |
| 906 | 919 | |
| 907 | 920 | `match` on an integer runs the arm whose labels hold its value: |
| 908 | 921 | |
| @@ -2041,6 +2054,8 @@ | ||
| 2041 | 2054 | `ERROR`, which makes the procedure it stands in return that error |
| 2042 | 2055 | when it isn't `nil` (sections 2, 5.8, 6, 7.8 and appendix B). `try` |
| 2043 | 2056 | 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). | |
| 2044 | 2059 | |
| 2045 | 2060 | ## Appendix A. What an implementation chooses |
| 2046 | 2061 |
| @@ -1600,7 +1600,7 @@ | ||
| 1600 | 1600 | |
| 1601 | 1601 | procedure MatchStatement(const start: TPos; ind: longint); |
| 1602 | 1602 | 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; | |
| 1604 | 1604 | seen: array[0..255] of boolean; hasElse, all, byValue: boolean; endAt: TPos; ls: TLabels; |
| 1605 | 1605 | begin |
| 1606 | 1606 | Next; |
| @@ -1633,18 +1633,23 @@ | ||
| 1633 | 1633 | end else if t^.form = fInt then |
| 1634 | 1634 | IntArm(t, ls, endL) |
| 1635 | 1635 | 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; | |
| 1643 | 1637 | 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 } | |
| 1645 | 1648 | ls.lo[ls.n] := c^.val; ls.hi[ls.n] := c^.val; |
| 1646 | 1649 | inc(ls.n); |
| 1647 | - end else MatchTag(p, c^.val, L); | |
| 1650 | + if tok <> sComma then break; | |
| 1651 | + Next; | |
| 1652 | + until false; | |
| 1648 | 1653 | OpenScope(NewScope); |
| 1649 | 1654 | if tok = sLparen then begin |
| 1650 | 1655 | Next; |
| @@ -1667,7 +1672,7 @@ | ||
| 1667 | 1672 | Expect(sRparen); |
| 1668 | 1673 | end; |
| 1669 | 1674 | 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; | |
| 1671 | 1676 | Statements; |
| 1672 | 1677 | CloseScope; |
| 1673 | 1678 | Jump(endL); |
| @@ -34,7 +34,7 @@ | ||
| 34 | 34 | { what git describe says, made by make: 0.3.0 at the tag v0.3.0, |
| 35 | 35 | 0.3.0-5-g38d29a8 five commits past it } |
| 36 | 36 | 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 } | |
| 38 | 38 | MemfdCreate = 319; { the system call; FPC 3.2.2 has no name for it } |
| 39 | 39 | MfdCloexec = 1; { an ELF still executes: the kernel opens it first } |
| 40 | 40 |
| @@ -0,0 +1,4 @@ | ||
| 1 | +conform/err/MatchEnumListMissing.raz:8:5: error: no arm for times | |
| 2 | + 8 | end; | |
| 3 | + | ^^^ | |
| 4 | +raz: 1 error |
| @@ -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 |
| @@ -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 |