raz / commit 5a422e6e

commit
5a422e6e6f510d7823ad92768c9d38672e6232b6
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
3a74493e
Warnings: what is never used, or only assigned; make check builds with -Werror

Objs are marked used and read where a name finds them; a var named
whole before := stays unread. At a module's end, if it had no errors,
its own decls and its procs' are merged by pos and warned of: an
import, a const, type, var or proc not exported, a param, a var only
assigned. _x never. A generic module is warned of once.

lib/, examples/ and tools/ cleared (callbacks' params, results thrown
away take a _); test/err takes X.args, for test/err/Unused. The
summary is printed once.

patch · log

21 files changed, +224 -37

CLAUDE.md modified +1 -1

@@ -58,7 +58,7 @@
5858 2026-10.2, approved): the terminal, files, directories and the
5959 environment. `tools/Scan.raz` is theirs to use, as a tool, not part of
6060 the library. Stage 4, diagnostics (steps 19-27), is under way:
61-steps 19-24 are done. New work starts only on the owner's word. Keep
61+steps 19-25 are done. New work starts only on the owner's word. Keep
6262 `doc/compiler.md`'s table of lines and its routine names true when the
6363 compiler changes. Left for later at the owner's word: a rewrite of
6464 var parameters.

PLAN.md (history) modified +1 -1

@@ -258,7 +258,7 @@
258258 for `:=`, `&&`, `||`, `!`, `elif`, a missing `then` or `do`, a
259259 missing import. The machinery, *main*; the catalogue of slips
260260 and their tests, *agent*.
261-- [ ] 25. Warnings: an unused import; an unused constant, type,
261+- [x] 25. Warnings: an unused import; an unused constant, type,
262262 variable or procedure that isn't exported; an unused parameter
263263 of a procedure written in raz; a variable assigned but never
264264 read. A name starting with `_` is never warned about. `-Werror`

doc/compiler.md (history) modified +14 -3

@@ -10,13 +10,13 @@
1010 |---|---|---|---|
1111 | `src/diag.pas` | 267 | 191 | Messages: positions, source excerpts, colour, counts |
1212 | `src/scan.pas` | 687 | 553 | Symbols, literals, comments, positions |
13-| `src/sym.pas` | 578 | 479 | Types, objects, scopes, layout |
13+| `src/sym.pas` | 583 | 483 | Types, objects, scopes, layout |
1414 | `src/x64.pas` | 682 | 548 | Code buffer, chunks, fixups, line notes, instruction encoder |
1515 | `src/gen.pas` | 1,515 | 1,319 | Items: loading, storing, copying, frames, calls |
16-| `src/parse.pas` | 2,151 | 1,955 | Declarations, statements, expressions, built-ins, recovery |
16+| `src/parse.pas` | 2,241 | 2,028 | Declarations, statements, expressions, built-ins, recovery, warnings |
1717 | `src/link.pas` | 131 | 95 | Tree shaking, layout, patching |
1818 | `src/elf.pas` | 425 | 351 | Static and dynamic ELF, symbol table, line numbers |
19-| `src/raz.pas` | 220 | 173 | The command line, the entry points |
19+| `src/raz.pas` | 221 | 174 | The command line, the entry points |
2020
2121 Every file opens with a comment that says what it is, what it depends
2222 on and what it leaves out. Read those first; they are the map.
@@ -346,6 +346,17 @@
346346 aren't reported, since they follow from one that was. Nothing breaks
347347 for the half-made code: once there is an error, no executable is
348348 written.
349+
350+**Warnings.** `Declare` keeps each module's declarations in order in
351+two lists, through `link`: its own and its procedures', parameters
352+and a match's names for fields among them. `Named` marks an object
353+`used` and `read` wherever a name finds it, except a procedure naming
354+itself; `LeftSide` puts `read` back as it was for a variable named
355+whole before `:=`, which is written, not read. At the end of a module
356+with no errors, `Warnings` merges the two lists by position and `Warn`
357+reports what isn't exported, doesn't start with `_`, and was never
358+used, or, for a variable, only assigned. A generic module's instances
359+share its text, so only the first is warned of.
349360
350361 The built-in procedures are in `Builtin` (and `New_`, `Atomic`): each
351362 parses its own arguments, since `SIZE` takes a type and `INC` a

examples/Words.raz (history) modified +3 -3

@@ -9,7 +9,7 @@
99 proc main*;
1010 var
1111 counts: Count.Map; order: Names.List; n: ^Names.Node;
12- i, start, k, total: I64; found, ok: BOOL; w: []U8;
12+ i, start, k, total: I64; found, _ok: BOOL; w: []U8;
1313 begin
1414 Count.init(ADR(counts), Heap.heap);
1515 Names.init(ADR(order), Heap.heap);
@@ -19,8 +19,8 @@
1919 w := Text[start..i];
2020 INC(total);
2121 k, found := Count.get(ADR(counts), w);
22- if not found then ok := Names.push(ADR(order), w); end;
23- ok := Count.put(ADR(counts), w, k + 1);
22+ if not found then _ok := Names.push(ADR(order), w); end;
23+ _ok := Count.put(ADR(counts), w, k + 1);
2424 start := i + 1;
2525 end;
2626 end;

examples/Workers.raz (history) modified +1 -1

@@ -21,7 +21,7 @@
2121 return s;
2222 end;
2323
24-proc work(arg: ^U8);
24+proc work(_arg: ^U8);
2525 var n, r: I64;
2626 begin
2727 n := XADD(ADR(next), 1);

lib/Arena.raz (history) modified +1 -1

@@ -21,7 +21,7 @@
2121 return ar^.buf + at;
2222 end;
2323
24-proc free(a: ^Mem.Allocator; p: ^U8);
24+proc free(_a: ^Mem.Allocator; _p: ^U8);
2525 begin
2626 end;
2727

lib/Heap.raz (history) modified +2 -2

@@ -40,7 +40,7 @@
4040
4141 (* size bytes aligned to align, or nil: also for a size below zero or
4242 too big, and an alignment that isn't a power of two up to a page. *)
43-proc alloc(a: ^Mem.Allocator; size, align: I64): ^U8;
43+proc alloc(_a: ^Mem.Allocator; size, align: I64): ^U8;
4444 var c, n: I64; b: ^Block; p: ^U8;
4545 begin
4646 if (size < 0) or (size > Largest) or (align < 1) or (align > Mem.Page)
@@ -77,7 +77,7 @@
7777 return give(p, c);
7878 end;
7979
80-proc free(a: ^Mem.Allocator; p: ^U8);
80+proc free(_a: ^Mem.Allocator; p: ^U8);
8181 var h: ^Head; b: ^Block; c: I64;
8282 begin
8383 if p = nil then return; end;

lib/List.raz (history) modified +2 -2

@@ -60,9 +60,9 @@
6060 end;
6161
6262 proc clear*(l: ^List);
63-var ok: BOOL; v: T;
63+var _ok: BOOL; _v: T;
6464 begin
65- while l^.head # nil do v, ok := pop(l); end;
65+ while l^.head # nil do _v, _ok := pop(l); end;
6666 end;
6767
6868 end List.

lib/Thread.linux-x86_64.raz (history) modified +1 -1

@@ -128,7 +128,7 @@
128128 testCount: I64;
129129 wave: [1000]^Thread;
130130
131-proc testWork(arg: ^U8);
131+proc testWork(_arg: ^U8);
132132 begin
133133 lock(ADR(testLock));
134134 INC(testCount);

src/parse.pas modified +98 -8

@@ -55,6 +55,7 @@
5555 fwdPos: array[0..255] of TPos; { where each names its type }
5656 numFwd: longint;
5757 lastCalled: PObj; { the procedure the last call was of, if it had a name }
58+ curProc: PObj; { the procedure being compiled, or nil }
5859 declExported: boolean; { the export mark of the declaration being read }
5960 curLoop: PLoop; { the innermost loop, or nil }
6061 defers: array[0..63] of longint; { the deferred statements in force }
@@ -110,8 +111,9 @@
110111 end;
111112 end;
112113
113-{ Declares o in the innermost scope; a module's own declarations are
114- also kept in order, for the interface check. }
114+{ Declares o in the innermost scope. Its module keeps its declarations
115+ in order: its own, for the interface check, and its procedures', to
116+ warn of those never used. }
115117 procedure Declare(o: PObj);
116118 begin
117119 Insert(o, TopScope);
@@ -119,9 +121,22 @@
119121 if curModule^.last = nil then curModule^.first := o
120122 else curModule^.last^.link := o;
121123 curModule^.last := o;
124+ end else begin
125+ if curModule^.lastLocal = nil then curModule^.locals := o
126+ else curModule^.lastLocal^.link := o;
127+ curModule^.lastLocal := o;
122128 end;
123129 end;
124130
131+{ o is named: a procedure naming itself doesn't count }
132+procedure Named(o: PObj);
133+begin
134+ if o <> curProc then begin
135+ o^.used := true;
136+ o^.read := true;
137+ end;
138+end;
139+
125140 { Recovery
126141
127142 After an error the parser goes on with the next statement or
@@ -284,6 +299,7 @@
284299 Fail;
285300 end;
286301 if o^.typ = tPoison then quiet := true;
302+ Named(o);
287303 Next;
288304 if o^.cls = oModule then begin
289305 Expect(sPeriod);
@@ -516,6 +532,7 @@
516532 o := NewObj(oConst, id, t);
517533 o^.val := t^.len;
518534 o^.exported := declExported;
535+ o^.used := true; { an enumeration's names are its type's, warned of with it }
519536 Declare(o);
520537 if last = nil then t^.fields := o else last^.next := o;
521538 last := o;
@@ -1177,6 +1194,7 @@
11771194 if tok <> sIdent then Expected('a name');
11781195 o := Lookup(id);
11791196 if o = nil then begin NotDeclared(TokPos, id); Fail end;
1197+ Named(o);
11801198 if (o^.cls <> oVar) or not (o^.typ^.form in [fInt, fEnum]) then
11811199 if o^.cls = oVar then
11821200 Mark('a for loop needs an integer or enumeration variable, found ' + TypeName(o^.typ))
@@ -1261,7 +1279,7 @@
12611279 o := NewObj(oVar, id, f^.typ);
12621280 o^.lev := 1; o^.ind := true; o^.isVar := true;
12631281 o^.val := p; o^.off := f^.val;
1264- Insert(o, TopScope);
1282+ Declare(o);
12651283 f := f^.next;
12661284 inc(n);
12671285 Next;
@@ -1299,6 +1317,20 @@
12991317 else Subject := 'a value';
13001318 end;
13011319
1320+{ The designator a statement starts with. A variable named whole
1321+ before := is assigned, not read: naming it there leaves it as unread
1322+ as it was. }
1323+procedure LeftSide(var x: TItem; var called: boolean);
1324+var o: PObj; wasRead: boolean; n: longint;
1325+begin
1326+ n := id;
1327+ o := Lookup(n);
1328+ wasRead := (o <> nil) and o^.read;
1329+ Designator(x, called);
1330+ if (tok in [sBecomes, sComma]) and (x.pos.b - x.pos.a = length(NameOf(n))) then
1331+ o^.read := wasRead;
1332+end;
1333+
13021334 { a, b := f(x): the variables first, left to right, then the call;
13031335 then each result to its variable, in order. }
13041336 procedure MultiAssign(var x: TItem; first: longint);
@@ -1315,7 +1347,7 @@
13151347 if n > High(d) then Mark('more than ' + IntStr(High(d) + 1) + ' variables in one assignment');
13161348 Next;
13171349 dn[n] := id;
1318- Designator(d[n], called);
1350+ LeftSide(d[n], called);
13191351 until false;
13201352 Expect(sBecomes);
13211353 Designator(y, called);
@@ -1378,7 +1410,7 @@
13781410 m := TempMark;
13791411 case tok of
13801412 sIdent: begin
1381- Designator(x, called);
1413+ LeftSide(x, called);
13821414 if tok = sBecomes then begin
13831415 if (x.mode <> mVar) or not x.isVar then MarkAt(x.pos, 'can''t assign to ' + Subject(x, first));
13841416 Save(x);
@@ -1501,8 +1533,10 @@
15011533 q := sig^.fields;
15021534 while q <> nil do begin
15031535 o := NewObj(oVar, q^.name, q^.typ);
1536+ o^.pos := q^.pos;
15041537 o^.lev := 1;
15051538 o^.isVar := q^.isVar;
1539+ o^.param := true;
15061540 if last = nil then params := o else last^.next := o;
15071541 last := o;
15081542 q := q^.next;
@@ -1512,9 +1546,10 @@
15121546 o := params;
15131547 while o <> nil do begin
15141548 q := o^.next;
1515- Insert(o, TopScope);
1549+ Declare(o);
15161550 o := q;
15171551 end;
1552+ curProc := p;
15181553 Declarations(false);
15191554 Expect(sBegin);
15201555 old := curResult;
@@ -1525,6 +1560,7 @@
15251560 Expect(sEnd);
15261561 EndProc(p^.chunk);
15271562 curResult := old;
1563+ curProc := nil;
15281564 CloseScope;
15291565 end;
15301566
@@ -1796,7 +1832,10 @@
17961832 if (o = nil) or (o^.cls <> oType) then begin
17971833 NotDeclared(fwdPos[i], fwdTypes[i]^.fwd);
17981834 fwdTypes[i]^.base := tPoison;
1799- end else fwdTypes[i]^.base := o^.typ;
1835+ end else begin
1836+ fwdTypes[i]^.base := o^.typ;
1837+ Named(o);
1838+ end;
18001839 fwdTypes[i]^.fwd := -1;
18011840 end;
18021841 end;
@@ -1862,7 +1901,9 @@
18621901 if tok <> sIdent then Expected('a name');
18631902 if i >= m^.args.n then MarkAt(m^.args.at, NameOf(m^.name) + ' needs a type for ' + NameOf(id));
18641903 if m^.args.o[i] <> nil then MarkAt(m^.args.pos[i], NameOf(m^.name) + ' needs a type for ' + NameOf(id));
1865- Declare(NewObj(oType, id, m^.args.t[i]));
1904+ o := NewObj(oType, id, m^.args.t[i]);
1905+ o^.used := true; { a parameter of the module, not a declaration }
1906+ Declare(o);
18661907 s := s + TypeName(m^.args.t[i]) + ',';
18671908 inc(i);
18681909 Next;
@@ -1887,6 +1928,7 @@
18871928 Finish;
18881929 end;
18891930 o^.typ := a^.typ; o^.chunk := a^.chunk; o^.isCode := a^.isCode; o^.ext := a^.ext;
1931+ o^.used := true;
18901932 Declare(o);
18911933 s := s + NameOf(a^.module^.name) + '.' + NameOf(a^.name) + ',';
18921934 inc(i);
@@ -1897,6 +1939,52 @@
18971939 m^.sname := Name(s);
18981940 end;
18991941
1942+{ Warns of o if it is never used, or a variable only assigned. What
1943+ is exported may be used elsewhere, and a name that starts with _ says
1944+ it is meant to go unused. Writing a var parameter, a match's name for
1945+ a field or C's variable is what it is for. }
1946+procedure Warn(o: PObj);
1947+var s: shortstring;
1948+begin
1949+ s := NameOf(o^.name);
1950+ if o^.exported or (s[1] = '_') then exit;
1951+ if o^.used and (o^.read or (o^.cls <> oVar) or o^.isVar or o^.ext) then exit;
1952+ case o^.cls of
1953+ oConst: s := 'constant ' + s;
1954+ oType: s := 'type ' + s;
1955+ oVar: if o^.param then s := 'parameter ' + s else s := 'variable ' + s;
1956+ oProc: s := 'procedure ' + s;
1957+ oModule: s := 'module ' + s;
1958+ else exit;
1959+ end;
1960+ if o^.used then Warning(o^.pos, s + ' is assigned but never read')
1961+ else if o^.cls = oModule then Warning(o^.pos, s + ' is imported but never used')
1962+ else Warning(o^.pos, s + ' is never used');
1963+ if not o^.used and (o^.param or o^.ind) then
1964+ Help('if it must be there, call it _' + NameOf(o^.name));
1965+end;
1966+
1967+{ The warnings of module m, by where each declaration is: its own
1968+ declarations and its procedures' are two lists, each in order. The
1969+ instances of a generic module share its text, and so its warnings:
1970+ only the first is warned of. }
1971+procedure Warnings(m: PModule);
1972+var a, b: PObj; n: PModule;
1973+begin
1974+ n := firstModule;
1975+ while (n <> nil) and (n^.name <> m^.name) do n := n^.next;
1976+ if n <> nil then exit;
1977+ a := m^.first; b := m^.locals;
1978+ while (a <> nil) or (b <> nil) do
1979+ if (b = nil) or (a <> nil) and (a^.pos.a < b^.pos.a) then begin
1980+ Warn(a);
1981+ a := a^.link;
1982+ end else begin
1983+ Warn(b);
1984+ b := b^.link;
1985+ end;
1986+end;
1987+
19001988 { Modules being compiled, not yet finished: for finding a cycle. }
19011989 var
19021990 pending: array[0..63] of PModule;
@@ -1964,6 +2052,7 @@
19642052 iargs.at := SpanFrom(start);
19652053 im := ImportModule(mname, iargs);
19662054 o := NewObj(oModule, alias, nil);
2055+ o^.pos := start;
19672056 o^.module := im;
19682057 Declare(o);
19692058 New(imp);
@@ -2014,6 +2103,7 @@
20142103 if (o^.cls = oProc) and o^.fwd then Error(TokPos, NameOf(o^.name) + ' is declared forward but never defined');
20152104 o := o^.link;
20162105 end;
2106+ if (errors = 0) and not checkOnly then Warnings(m);
20172107 if errors > 0 then Finish; { a module with errors stops the compiler after it }
20182108 CloseScope;
20192109 m^.done := true;

src/raz.pas modified +3 -2

@@ -142,7 +142,7 @@
142142 end;
143143
144144 m := CompileMain(path);
145- Finish;
145+ if errors > 0 then Finish;
146146
147147 Use(m);
148148 rt := firstModule;
@@ -155,9 +155,10 @@
155155 if (main^.cls <> oProc) or not main^.exported then Error(main^.pos, 'main must be an exported procedure')
156156 else if (main^.typ^.len <> 0) or ((main^.typ^.base <> nil) and (main^.typ^.base <> tI64)) then
157157 Error(main^.pos, 'main must be proc main* or proc main*: I64');
158- Finish;
158+ if errors > 0 then Finish;
159159 hasResult := main^.typ^.base <> nil;
160160 end;
161+ Finish;
161162
162163 if rt = nil then Fatal('can''t find module Rt');
163164 dynamic := UsesC;

src/sym.pas modified +6 -1

@@ -66,13 +66,17 @@
6666 ind: boolean; { oVar: the frame slot holds the variable's address }
6767 off: int64; { oVar with ind: added to that address }
6868 isVar: boolean; { a var parameter }
69+ param: boolean; { oVar: a parameter }
70+ used: boolean; { named somewhere but in its own body }
71+ read: boolean; { oVar: named other than as what := assigns }
6972 fwd: boolean; { oProc: declared forward, no body yet }
7073 isCode: boolean; { oProc: a code procedure }
7174 ext: boolean; { oProc, oVar: C's, reached through its chunk, which
7275 holds its address }
7376 fields: PObj; { oCase: its fields }
7477 module: PModule; { oModule: the module; others: where declared }
75- link: PObj; { the next top-level declaration of its module }
78+ link: PObj; { the next declaration of its module, top-level or
79+ local }
7680 end;
7781
7882 { The arguments of a generic module's instance: a type, or a
@@ -103,6 +107,7 @@
103107 scope: longint;
104108 path: shortstring;
105109 first, last: PObj; { its top-level declarations, in order }
110+ locals, lastLocal: PObj; { its procedures' declarations, in order }
106111 imports: PImport;
107112 body: longint; { the chunk of its body, or -1 }
108113 done: boolean; { compiled to the end }

test/check.sh (history) modified +13 -7

@@ -7,7 +7,9 @@
77 # X.status its exit status (optional; 0 if missing)
88 # A program without X.expect is compiled, not run. test/libc puts
99 # lib/Sys.raz, over the C library, before the system call one.
10-# Programs in test/err must not compile, and must print X.err. Then
10+# Programs in test/err must not compile, and must print X.err; there
11+# X.args holds the compiler's options. The examples, the tools and the
12+# library's tests are compiled with -Werror, so warnings fail them. Then
1113 # the version, tools/Doc.raz, the report's examples, tools/Pretty.raz,
1214 # and the library's own tests.
1315
@@ -19,7 +21,9 @@
1921
2022 run() { # run dir name
2123 dir=$1; name=$2
22- if ! $raz -I $dir/mods -o $out/$name $dir/$name.raz 2>$out/$name.cerr; then
24+ flags=
25+ [ $dir = examples ] && flags=-Werror
26+ if ! $raz $flags -I $dir/mods -o $out/$name $dir/$name.raz 2>$out/$name.cerr; then
2327 echo "FAIL $dir/$name: doesn't compile: $(cat $out/$name.cerr)"
2428 fail=$((fail + 1)); return
2529 fi
@@ -61,7 +65,9 @@
6165 runs test/libc/Through.raz 2
6266 for f in test/err/*.raz; do
6367 name=$(basename $f .raz)
64- if $raz -I test/err/mods -I test/run/mods -o $out/$name $f 2>$out/$name.cerr; then
68+ flags=
69+ [ -f test/err/$name.args ] && flags=$(cat test/err/$name.args)
70+ if $raz $flags -I test/err/mods -I test/run/mods -o $out/$name $f 2>$out/$name.cerr; then
6571 echo "FAIL $f: compiles"
6672 fail=$((fail + 1))
6773 elif ! cmp -s test/err/$name.err $out/$name.cerr; then
@@ -77,7 +83,7 @@
7783 else echo "FAIL raz --version: not report $want"; fail=$((fail + 1)); fi
7884
7985 # tools/Doc.raz: on every library module, and as test/doc expects
80-if ./raz -o $out/Doc tools/Doc.raz 2>$out/Doc.cerr; then
86+if ./raz -Werror -o $out/Doc tools/Doc.raz 2>$out/Doc.cerr; then
8187 for f in lib/*.raz; do
8288 if ! $out/Doc $f > $out/doc.out; then echo "FAIL Doc $f"; fail=$((fail + 1)); fi
8389 done
@@ -105,7 +111,7 @@
105111
106112 # tools/Pretty.raz: each test/pretty/X.raz comes out as X.expect, which
107113 # comes out as it is; so do the library, the examples and the tools
108-if ./raz -o $out/Pretty tools/Pretty.raz 2>$out/Pretty.cerr; then
114+if ./raz -Werror -o $out/Pretty tools/Pretty.raz 2>$out/Pretty.cerr; then
109115 for f in test/pretty/*.raz; do
110116 want=test/pretty/$(basename $f .raz).expect
111117 if $out/Pretty $f | cmp -s - $want && $out/Pretty $want | cmp -s - $want; then
@@ -144,7 +150,7 @@
144150 fail=$((fail + 1))
145151 else pass=$((pass + 1)); fi
146152 }
147-if ./raz -o $out/Mutate tools/Mutate.raz 2>$out/Mutate.cerr; then
153+if ./raz -Werror -o $out/Mutate tools/Mutate.raz 2>$out/Mutate.cerr; then
148154 for f in examples/*.raz test/run/*.raz; do
149155 $raz -I $(dirname $f)/mods -o $out/mutant $f 2>/dev/null || continue
150156 for seed in ${FUZZ_SEEDS:-1 2 3}; do fuzz $f $seed; done
@@ -158,7 +164,7 @@
158164 [ $f = lib/Sys.raz ] && continue
159165 grep -q '^proc main\*' $f || continue
160166 name=lib_$(basename $f .raz)
161- if ! $raz -o $out/$name $f 2>$out/$name.cerr; then
167+ if ! $raz -Werror -o $out/$name $f 2>$out/$name.cerr; then
162168 echo "FAIL $f: doesn't compile: $(cat $out/$name.cerr)"; fail=$((fail + 1))
163169 elif ! $out/$name > $out/$name.out 2>&1; then
164170 echo "FAIL $f: its test says $(cat $out/$name.out)"; fail=$((fail + 1))

test/err/DeclNotExported.err modified +4 -1

@@ -1,7 +1,10 @@
1+test/err/mods/DeclHidden.raz:3:7: warning: constant hidden is never used
2+ 3 | const hidden = 2;
3+ | ^^^^^^
14 test/err/DeclNotExported.raz:6:21: error: hidden isn't exported by DeclHidden
25 6 | n := DeclHidden.hidden;
36 | ^^^^^^
47 test/err/mods/DeclHidden.raz:3:7: note: hidden is declared here, without a *
58 3 | const hidden = 2;
69 | ^^^^^^
7-raz: 1 error
10+raz: 1 error, 1 warning

test/err/ScanMain.err modified +1 -1

@@ -1,4 +1,4 @@
11 test/err/ScanMain.raz:2:6: error: main must be proc main* or proc main*: I64
2- 2 | proc main*(n: I64);
2+ 2 | proc main*(_n: I64);
33 | ^^^^
44 raz: 1 error

test/err/ScanMain.raz modified +1 -1

@@ -1,5 +1,5 @@
11 module ScanMain;
2-proc main*(n: I64);
2+proc main*(_n: I64);
33 begin
44 end;
55 end ScanMain.

test/err/ThreadC.err modified +7 -0

@@ -1 +1,8 @@
1+test/err/ThreadC.raz:2:8: warning: module Thread is imported but never used
2+ 2 | import Thread, C;
3+ | ^^^^^^
4+test/err/ThreadC.raz:2:16: warning: module C is imported but never used
5+ 2 | import Thread, C;
6+ | ^
7+raz: 2 warnings
18 raz: Thread says link static, but C uses C

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

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

test/err/Unused.err (history) added +23 -0

@@ -0,0 +1,23 @@
1+test/err/Unused.raz:3:13: error: module Sys is imported but never used
2+ 3 | import Out, Sys;
3+ | ^^^
4+test/err/Unused.raz:6:5: error: constant N is never used
5+ 6 | N = 3; M* = 4; _K = 5;
6+ | ^
7+test/err/Unused.raz:9:5: error: type Color is never used
8+ 9 | Color = (red, green);
9+ | ^^^^^
10+test/err/Unused.raz:13:5: error: variable g is assigned but never read
11+ 13 | g, h, seen: I64;
12+ | ^
13+test/err/Unused.raz:15:6: error: procedure fact is never used
14+ 15 | proc fact(n: I64): I64; (* calling itself doesn't count *)
15+ | ^^^^
16+test/err/Unused.raz:21:14: error: parameter a is never used
17+ 21 | proc helper*(a, _b: Used; var r: I64);
18+ | ^
19+help: if it must be there, call it _a
20+test/err/Unused.raz:22:5: error: variable x is assigned but never read
21+ 22 | var x, y: I64; t: [4]I64;
22+ | ^
23+raz: 7 errors

test/err/Unused.raz (history) added +40 -0

@@ -0,0 +1,40 @@
1+module Unused;
2+(* What is never used is warned of, and -Werror makes it an error *)
3+import Out, Sys;
4+
5+const
6+ N = 3; M* = 4; _K = 5;
7+
8+type
9+ Color = (red, green);
10+ Used = I64;
11+
12+var
13+ g, h, seen: I64;
14+
15+proc fact(n: I64): I64; (* calling itself doesn't count *)
16+begin
17+ if n = 0 then return 1; end;
18+ return n * fact(n - 1);
19+end;
20+
21+proc helper*(a, _b: Used; var r: I64);
22+var x, y: I64; t: [4]I64;
23+begin
24+ x := 1;
25+ y := 2;
26+ y := y + 1;
27+ t[0] := 1;
28+ r := 0;
29+end;
30+
31+proc main*;
32+var i: I64;
33+begin
34+ g := 1;
35+ seen := h;
36+ for i := 0 to 2 do end;
37+ Out.int(seen);
38+end;
39+
40+end Unused.

test/err/mods/Rec.linux-x86_64.raz (history) modified +1 -1

@@ -1,4 +1,4 @@
11 module Rec;
22 type R* = record a*: I64; b: I64; end;
3-proc f*(r: ^R); begin end;
3+proc f*(_r: ^R); begin end;
44 end Rec.