From 5a422e6e6f510d7823ad92768c9d38672e6232b6 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Sun, 11 Oct 2026 10:37:00 +0100 Subject: [PATCH] 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. --- diff --git a/CLAUDE.md b/CLAUDE.md index 0321279..82ccfe6 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -58,7 +58,7 @@ 2026-10.2, approved): the terminal, files, directories and the environment. `tools/Scan.raz` is theirs to use, as a tool, not part of the library. Stage 4, diagnostics (steps 19-27), is under way: -steps 19-24 are done. New work starts only on the owner's word. Keep +steps 19-25 are done. New work starts only on the owner's word. Keep `doc/compiler.md`'s table of lines and its routine names true when the compiler changes. Left for later at the owner's word: a rewrite of var parameters. diff --git a/PLAN.md b/PLAN.md index 59ee5ed..2af938b 100644 --- a/PLAN.md +++ b/PLAN.md @@ -258,7 +258,7 @@ for `:=`, `&&`, `||`, `!`, `elif`, a missing `then` or `do`, a missing import. The machinery, *main*; the catalogue of slips and their tests, *agent*. -- [ ] 25. Warnings: an unused import; an unused constant, type, +- [x] 25. Warnings: an unused import; an unused constant, type, variable or procedure that isn't exported; an unused parameter of a procedure written in raz; a variable assigned but never read. A name starting with `_` is never warned about. `-Werror` diff --git a/doc/compiler.md b/doc/compiler.md index 292508f..2f93287 100644 --- a/doc/compiler.md +++ b/doc/compiler.md @@ -10,13 +10,13 @@ |---|---|---|---| | `src/diag.pas` | 267 | 191 | Messages: positions, source excerpts, colour, counts | | `src/scan.pas` | 687 | 553 | Symbols, literals, comments, positions | -| `src/sym.pas` | 578 | 479 | Types, objects, scopes, layout | +| `src/sym.pas` | 583 | 483 | Types, objects, scopes, layout | | `src/x64.pas` | 682 | 548 | Code buffer, chunks, fixups, line notes, instruction encoder | | `src/gen.pas` | 1,515 | 1,319 | Items: loading, storing, copying, frames, calls | -| `src/parse.pas` | 2,151 | 1,955 | Declarations, statements, expressions, built-ins, recovery | +| `src/parse.pas` | 2,241 | 2,028 | Declarations, statements, expressions, built-ins, recovery, warnings | | `src/link.pas` | 131 | 95 | Tree shaking, layout, patching | | `src/elf.pas` | 425 | 351 | Static and dynamic ELF, symbol table, line numbers | -| `src/raz.pas` | 220 | 173 | The command line, the entry points | +| `src/raz.pas` | 221 | 174 | The command line, the entry points | Every file opens with a comment that says what it is, what it depends on and what it leaves out. Read those first; they are the map. @@ -346,6 +346,17 @@ aren't reported, since they follow from one that was. Nothing breaks for the half-made code: once there is an error, no executable is written. + +**Warnings.** `Declare` keeps each module's declarations in order in +two lists, through `link`: its own and its procedures', parameters +and a match's names for fields among them. `Named` marks an object +`used` and `read` wherever a name finds it, except a procedure naming +itself; `LeftSide` puts `read` back as it was for a variable named +whole before `:=`, which is written, not read. At the end of a module +with no errors, `Warnings` merges the two lists by position and `Warn` +reports what isn't exported, doesn't start with `_`, and was never +used, or, for a variable, only assigned. A generic module's instances +share its text, so only the first is warned of. The built-in procedures are in `Builtin` (and `New_`, `Atomic`): each parses its own arguments, since `SIZE` takes a type and `INC` a diff --git a/examples/Words.raz b/examples/Words.raz index ee1eba9..0523de4 100644 --- a/examples/Words.raz +++ b/examples/Words.raz @@ -9,7 +9,7 @@ proc main*; var counts: Count.Map; order: Names.List; n: ^Names.Node; - i, start, k, total: I64; found, ok: BOOL; w: []U8; + i, start, k, total: I64; found, _ok: BOOL; w: []U8; begin Count.init(ADR(counts), Heap.heap); Names.init(ADR(order), Heap.heap); @@ -19,8 +19,8 @@ w := Text[start..i]; INC(total); k, found := Count.get(ADR(counts), w); - if not found then ok := Names.push(ADR(order), w); end; - ok := Count.put(ADR(counts), w, k + 1); + if not found then _ok := Names.push(ADR(order), w); end; + _ok := Count.put(ADR(counts), w, k + 1); start := i + 1; end; end; diff --git a/examples/Workers.raz b/examples/Workers.raz index cd95a50..a566fde 100644 --- a/examples/Workers.raz +++ b/examples/Workers.raz @@ -21,7 +21,7 @@ return s; end; -proc work(arg: ^U8); +proc work(_arg: ^U8); var n, r: I64; begin n := XADD(ADR(next), 1); diff --git a/lib/Arena.raz b/lib/Arena.raz index 278014c..e8d701d 100644 --- a/lib/Arena.raz +++ b/lib/Arena.raz @@ -21,7 +21,7 @@ return ar^.buf + at; end; -proc free(a: ^Mem.Allocator; p: ^U8); +proc free(_a: ^Mem.Allocator; _p: ^U8); begin end; diff --git a/lib/Heap.raz b/lib/Heap.raz index d51c8e5..c02ff8b 100644 --- a/lib/Heap.raz +++ b/lib/Heap.raz @@ -40,7 +40,7 @@ (* size bytes aligned to align, or nil: also for a size below zero or too big, and an alignment that isn't a power of two up to a page. *) -proc alloc(a: ^Mem.Allocator; size, align: I64): ^U8; +proc alloc(_a: ^Mem.Allocator; size, align: I64): ^U8; var c, n: I64; b: ^Block; p: ^U8; begin if (size < 0) or (size > Largest) or (align < 1) or (align > Mem.Page) @@ -77,7 +77,7 @@ return give(p, c); end; -proc free(a: ^Mem.Allocator; p: ^U8); +proc free(_a: ^Mem.Allocator; p: ^U8); var h: ^Head; b: ^Block; c: I64; begin if p = nil then return; end; diff --git a/lib/List.raz b/lib/List.raz index 13eeef2..80f8112 100644 --- a/lib/List.raz +++ b/lib/List.raz @@ -60,9 +60,9 @@ end; proc clear*(l: ^List); -var ok: BOOL; v: T; +var _ok: BOOL; _v: T; begin - while l^.head # nil do v, ok := pop(l); end; + while l^.head # nil do _v, _ok := pop(l); end; end; end List. diff --git a/lib/Thread.linux-x86_64.raz b/lib/Thread.linux-x86_64.raz index d9fdc57..49d5e0e 100644 --- a/lib/Thread.linux-x86_64.raz +++ b/lib/Thread.linux-x86_64.raz @@ -128,7 +128,7 @@ testCount: I64; wave: [1000]^Thread; -proc testWork(arg: ^U8); +proc testWork(_arg: ^U8); begin lock(ADR(testLock)); INC(testCount); diff --git a/src/parse.pas b/src/parse.pas index 69ba46f..e70a4b8 100644 --- a/src/parse.pas +++ b/src/parse.pas @@ -55,6 +55,7 @@ fwdPos: array[0..255] of TPos; { where each names its type } numFwd: longint; lastCalled: PObj; { the procedure the last call was of, if it had a name } + curProc: PObj; { the procedure being compiled, or nil } declExported: boolean; { the export mark of the declaration being read } curLoop: PLoop; { the innermost loop, or nil } defers: array[0..63] of longint; { the deferred statements in force } @@ -110,8 +111,9 @@ end; end; -{ Declares o in the innermost scope; a module's own declarations are - also kept in order, for the interface check. } +{ Declares o in the innermost scope. Its module keeps its declarations + in order: its own, for the interface check, and its procedures', to + warn of those never used. } procedure Declare(o: PObj); begin Insert(o, TopScope); @@ -119,9 +121,22 @@ if curModule^.last = nil then curModule^.first := o else curModule^.last^.link := o; curModule^.last := o; + end else begin + if curModule^.lastLocal = nil then curModule^.locals := o + else curModule^.lastLocal^.link := o; + curModule^.lastLocal := o; end; end; +{ o is named: a procedure naming itself doesn't count } +procedure Named(o: PObj); +begin + if o <> curProc then begin + o^.used := true; + o^.read := true; + end; +end; + { Recovery After an error the parser goes on with the next statement or @@ -284,6 +299,7 @@ Fail; end; if o^.typ = tPoison then quiet := true; + Named(o); Next; if o^.cls = oModule then begin Expect(sPeriod); @@ -516,6 +532,7 @@ o := NewObj(oConst, id, t); o^.val := t^.len; o^.exported := declExported; + o^.used := true; { an enumeration's names are its type's, warned of with it } Declare(o); if last = nil then t^.fields := o else last^.next := o; last := o; @@ -1177,6 +1194,7 @@ if tok <> sIdent then Expected('a name'); o := Lookup(id); if o = nil then begin NotDeclared(TokPos, id); Fail end; + Named(o); if (o^.cls <> oVar) or not (o^.typ^.form in [fInt, fEnum]) then if o^.cls = oVar then Mark('a for loop needs an integer or enumeration variable, found ' + TypeName(o^.typ)) @@ -1261,7 +1279,7 @@ o := NewObj(oVar, id, f^.typ); o^.lev := 1; o^.ind := true; o^.isVar := true; o^.val := p; o^.off := f^.val; - Insert(o, TopScope); + Declare(o); f := f^.next; inc(n); Next; @@ -1299,6 +1317,20 @@ else Subject := 'a value'; end; +{ The designator a statement starts with. A variable named whole + before := is assigned, not read: naming it there leaves it as unread + as it was. } +procedure LeftSide(var x: TItem; var called: boolean); +var o: PObj; wasRead: boolean; n: longint; +begin + n := id; + o := Lookup(n); + wasRead := (o <> nil) and o^.read; + Designator(x, called); + if (tok in [sBecomes, sComma]) and (x.pos.b - x.pos.a = length(NameOf(n))) then + o^.read := wasRead; +end; + { a, b := f(x): the variables first, left to right, then the call; then each result to its variable, in order. } procedure MultiAssign(var x: TItem; first: longint); @@ -1315,7 +1347,7 @@ if n > High(d) then Mark('more than ' + IntStr(High(d) + 1) + ' variables in one assignment'); Next; dn[n] := id; - Designator(d[n], called); + LeftSide(d[n], called); until false; Expect(sBecomes); Designator(y, called); @@ -1378,7 +1410,7 @@ m := TempMark; case tok of sIdent: begin - Designator(x, called); + LeftSide(x, called); if tok = sBecomes then begin if (x.mode <> mVar) or not x.isVar then MarkAt(x.pos, 'can''t assign to ' + Subject(x, first)); Save(x); @@ -1501,8 +1533,10 @@ q := sig^.fields; while q <> nil do begin o := NewObj(oVar, q^.name, q^.typ); + o^.pos := q^.pos; o^.lev := 1; o^.isVar := q^.isVar; + o^.param := true; if last = nil then params := o else last^.next := o; last := o; q := q^.next; @@ -1512,9 +1546,10 @@ o := params; while o <> nil do begin q := o^.next; - Insert(o, TopScope); + Declare(o); o := q; end; + curProc := p; Declarations(false); Expect(sBegin); old := curResult; @@ -1525,6 +1560,7 @@ Expect(sEnd); EndProc(p^.chunk); curResult := old; + curProc := nil; CloseScope; end; @@ -1796,7 +1832,10 @@ if (o = nil) or (o^.cls <> oType) then begin NotDeclared(fwdPos[i], fwdTypes[i]^.fwd); fwdTypes[i]^.base := tPoison; - end else fwdTypes[i]^.base := o^.typ; + end else begin + fwdTypes[i]^.base := o^.typ; + Named(o); + end; fwdTypes[i]^.fwd := -1; end; end; @@ -1862,7 +1901,9 @@ if tok <> sIdent then Expected('a name'); if i >= m^.args.n then MarkAt(m^.args.at, NameOf(m^.name) + ' needs a type for ' + NameOf(id)); if m^.args.o[i] <> nil then MarkAt(m^.args.pos[i], NameOf(m^.name) + ' needs a type for ' + NameOf(id)); - Declare(NewObj(oType, id, m^.args.t[i])); + o := NewObj(oType, id, m^.args.t[i]); + o^.used := true; { a parameter of the module, not a declaration } + Declare(o); s := s + TypeName(m^.args.t[i]) + ','; inc(i); Next; @@ -1887,6 +1928,7 @@ Finish; end; o^.typ := a^.typ; o^.chunk := a^.chunk; o^.isCode := a^.isCode; o^.ext := a^.ext; + o^.used := true; Declare(o); s := s + NameOf(a^.module^.name) + '.' + NameOf(a^.name) + ','; inc(i); @@ -1897,6 +1939,52 @@ m^.sname := Name(s); end; +{ Warns of o if it is never used, or a variable only assigned. What + is exported may be used elsewhere, and a name that starts with _ says + it is meant to go unused. Writing a var parameter, a match's name for + a field or C's variable is what it is for. } +procedure Warn(o: PObj); +var s: shortstring; +begin + s := NameOf(o^.name); + if o^.exported or (s[1] = '_') then exit; + if o^.used and (o^.read or (o^.cls <> oVar) or o^.isVar or o^.ext) then exit; + case o^.cls of + oConst: s := 'constant ' + s; + oType: s := 'type ' + s; + oVar: if o^.param then s := 'parameter ' + s else s := 'variable ' + s; + oProc: s := 'procedure ' + s; + oModule: s := 'module ' + s; + else exit; + end; + if o^.used then Warning(o^.pos, s + ' is assigned but never read') + else if o^.cls = oModule then Warning(o^.pos, s + ' is imported but never used') + else Warning(o^.pos, s + ' is never used'); + if not o^.used and (o^.param or o^.ind) then + Help('if it must be there, call it _' + NameOf(o^.name)); +end; + +{ The warnings of module m, by where each declaration is: its own + declarations and its procedures' are two lists, each in order. The + instances of a generic module share its text, and so its warnings: + only the first is warned of. } +procedure Warnings(m: PModule); +var a, b: PObj; n: PModule; +begin + n := firstModule; + while (n <> nil) and (n^.name <> m^.name) do n := n^.next; + if n <> nil then exit; + a := m^.first; b := m^.locals; + while (a <> nil) or (b <> nil) do + if (b = nil) or (a <> nil) and (a^.pos.a < b^.pos.a) then begin + Warn(a); + a := a^.link; + end else begin + Warn(b); + b := b^.link; + end; +end; + { Modules being compiled, not yet finished: for finding a cycle. } var pending: array[0..63] of PModule; @@ -1964,6 +2052,7 @@ iargs.at := SpanFrom(start); im := ImportModule(mname, iargs); o := NewObj(oModule, alias, nil); + o^.pos := start; o^.module := im; Declare(o); New(imp); @@ -2014,6 +2103,7 @@ if (o^.cls = oProc) and o^.fwd then Error(TokPos, NameOf(o^.name) + ' is declared forward but never defined'); o := o^.link; end; + if (errors = 0) and not checkOnly then Warnings(m); if errors > 0 then Finish; { a module with errors stops the compiler after it } CloseScope; m^.done := true; diff --git a/src/raz.pas b/src/raz.pas index 5355a71..01ffd2e 100644 --- a/src/raz.pas +++ b/src/raz.pas @@ -142,7 +142,7 @@ end; m := CompileMain(path); - Finish; + if errors > 0 then Finish; Use(m); rt := firstModule; @@ -155,9 +155,10 @@ if (main^.cls <> oProc) or not main^.exported then Error(main^.pos, 'main must be an exported procedure') else if (main^.typ^.len <> 0) or ((main^.typ^.base <> nil) and (main^.typ^.base <> tI64)) then Error(main^.pos, 'main must be proc main* or proc main*: I64'); - Finish; + if errors > 0 then Finish; hasResult := main^.typ^.base <> nil; end; + Finish; if rt = nil then Fatal('can''t find module Rt'); dynamic := UsesC; diff --git a/src/sym.pas b/src/sym.pas index a939a6d..cc0ae56 100644 --- a/src/sym.pas +++ b/src/sym.pas @@ -66,13 +66,17 @@ ind: boolean; { oVar: the frame slot holds the variable's address } off: int64; { oVar with ind: added to that address } isVar: boolean; { a var parameter } + param: boolean; { oVar: a parameter } + used: boolean; { named somewhere but in its own body } + read: boolean; { oVar: named other than as what := assigns } fwd: boolean; { oProc: declared forward, no body yet } isCode: boolean; { oProc: a code procedure } ext: boolean; { oProc, oVar: C's, reached through its chunk, which holds its address } fields: PObj; { oCase: its fields } module: PModule; { oModule: the module; others: where declared } - link: PObj; { the next top-level declaration of its module } + link: PObj; { the next declaration of its module, top-level or + local } end; { The arguments of a generic module's instance: a type, or a @@ -103,6 +107,7 @@ scope: longint; path: shortstring; first, last: PObj; { its top-level declarations, in order } + locals, lastLocal: PObj; { its procedures' declarations, in order } imports: PImport; body: longint; { the chunk of its body, or -1 } done: boolean; { compiled to the end } diff --git a/test/check.sh b/test/check.sh index 5fd96bd..ac0901d 100755 --- a/test/check.sh +++ b/test/check.sh @@ -7,7 +7,9 @@ # X.status its exit status (optional; 0 if missing) # A program without X.expect is compiled, not run. test/libc puts # lib/Sys.raz, over the C library, before the system call one. -# Programs in test/err must not compile, and must print X.err. Then +# Programs in test/err must not compile, and must print X.err; there +# X.args holds the compiler's options. The examples, the tools and the +# library's tests are compiled with -Werror, so warnings fail them. Then # the version, tools/Doc.raz, the report's examples, tools/Pretty.raz, # and the library's own tests. @@ -19,7 +21,9 @@ run() { # run dir name dir=$1; name=$2 - if ! $raz -I $dir/mods -o $out/$name $dir/$name.raz 2>$out/$name.cerr; then + flags= + [ $dir = examples ] && flags=-Werror + if ! $raz $flags -I $dir/mods -o $out/$name $dir/$name.raz 2>$out/$name.cerr; then echo "FAIL $dir/$name: doesn't compile: $(cat $out/$name.cerr)" fail=$((fail + 1)); return fi @@ -61,7 +65,9 @@ runs test/libc/Through.raz 2 for f in test/err/*.raz; do name=$(basename $f .raz) - if $raz -I test/err/mods -I test/run/mods -o $out/$name $f 2>$out/$name.cerr; then + flags= + [ -f test/err/$name.args ] && flags=$(cat test/err/$name.args) + if $raz $flags -I test/err/mods -I test/run/mods -o $out/$name $f 2>$out/$name.cerr; then echo "FAIL $f: compiles" fail=$((fail + 1)) elif ! cmp -s test/err/$name.err $out/$name.cerr; then @@ -77,7 +83,7 @@ else echo "FAIL raz --version: not report $want"; fail=$((fail + 1)); fi # tools/Doc.raz: on every library module, and as test/doc expects -if ./raz -o $out/Doc tools/Doc.raz 2>$out/Doc.cerr; then +if ./raz -Werror -o $out/Doc tools/Doc.raz 2>$out/Doc.cerr; then for f in lib/*.raz; do if ! $out/Doc $f > $out/doc.out; then echo "FAIL Doc $f"; fail=$((fail + 1)); fi done @@ -105,7 +111,7 @@ # tools/Pretty.raz: each test/pretty/X.raz comes out as X.expect, which # comes out as it is; so do the library, the examples and the tools -if ./raz -o $out/Pretty tools/Pretty.raz 2>$out/Pretty.cerr; then +if ./raz -Werror -o $out/Pretty tools/Pretty.raz 2>$out/Pretty.cerr; then for f in test/pretty/*.raz; do want=test/pretty/$(basename $f .raz).expect if $out/Pretty $f | cmp -s - $want && $out/Pretty $want | cmp -s - $want; then @@ -144,7 +150,7 @@ fail=$((fail + 1)) else pass=$((pass + 1)); fi } -if ./raz -o $out/Mutate tools/Mutate.raz 2>$out/Mutate.cerr; then +if ./raz -Werror -o $out/Mutate tools/Mutate.raz 2>$out/Mutate.cerr; then for f in examples/*.raz test/run/*.raz; do $raz -I $(dirname $f)/mods -o $out/mutant $f 2>/dev/null || continue for seed in ${FUZZ_SEEDS:-1 2 3}; do fuzz $f $seed; done @@ -158,7 +164,7 @@ [ $f = lib/Sys.raz ] && continue grep -q '^proc main\*' $f || continue name=lib_$(basename $f .raz) - if ! $raz -o $out/$name $f 2>$out/$name.cerr; then + if ! $raz -Werror -o $out/$name $f 2>$out/$name.cerr; then echo "FAIL $f: doesn't compile: $(cat $out/$name.cerr)"; fail=$((fail + 1)) elif ! $out/$name > $out/$name.out 2>&1; then echo "FAIL $f: its test says $(cat $out/$name.out)"; fail=$((fail + 1)) diff --git a/test/err/DeclNotExported.err b/test/err/DeclNotExported.err index ca471ae..8943809 100644 --- a/test/err/DeclNotExported.err +++ b/test/err/DeclNotExported.err @@ -1,7 +1,10 @@ +test/err/mods/DeclHidden.raz:3:7: warning: constant hidden is never used + 3 | const hidden = 2; + | ^^^^^^ test/err/DeclNotExported.raz:6:21: error: hidden isn't exported by DeclHidden 6 | n := DeclHidden.hidden; | ^^^^^^ test/err/mods/DeclHidden.raz:3:7: note: hidden is declared here, without a * 3 | const hidden = 2; | ^^^^^^ -raz: 1 error +raz: 1 error, 1 warning diff --git a/test/err/ScanMain.err b/test/err/ScanMain.err index 353e780..a001f2a 100644 --- a/test/err/ScanMain.err +++ b/test/err/ScanMain.err @@ -1,4 +1,4 @@ test/err/ScanMain.raz:2:6: error: main must be proc main* or proc main*: I64 - 2 | proc main*(n: I64); + 2 | proc main*(_n: I64); | ^^^^ raz: 1 error diff --git a/test/err/ScanMain.raz b/test/err/ScanMain.raz index 831755f..49d84ec 100644 --- a/test/err/ScanMain.raz +++ b/test/err/ScanMain.raz @@ -1,5 +1,5 @@ module ScanMain; -proc main*(n: I64); +proc main*(_n: I64); begin end; end ScanMain. diff --git a/test/err/ThreadC.err b/test/err/ThreadC.err index c382840..12e417e 100644 --- a/test/err/ThreadC.err +++ b/test/err/ThreadC.err @@ -1 +1,8 @@ +test/err/ThreadC.raz:2:8: warning: module Thread is imported but never used + 2 | import Thread, C; + | ^^^^^^ +test/err/ThreadC.raz:2:16: warning: module C is imported but never used + 2 | import Thread, C; + | ^ +raz: 2 warnings raz: Thread says link static, but C uses C diff --git a/test/err/Unused.args b/test/err/Unused.args new file mode 100644 index 0000000..2f41be6 --- /dev/null +++ b/test/err/Unused.args @@ -0,0 +1 @@ +-Werror diff --git a/test/err/Unused.err b/test/err/Unused.err new file mode 100644 index 0000000..5ada0c9 --- /dev/null +++ b/test/err/Unused.err @@ -0,0 +1,23 @@ +test/err/Unused.raz:3:13: error: module Sys is imported but never used + 3 | import Out, Sys; + | ^^^ +test/err/Unused.raz:6:5: error: constant N is never used + 6 | N = 3; M* = 4; _K = 5; + | ^ +test/err/Unused.raz:9:5: error: type Color is never used + 9 | Color = (red, green); + | ^^^^^ +test/err/Unused.raz:13:5: error: variable g is assigned but never read + 13 | g, h, seen: I64; + | ^ +test/err/Unused.raz:15:6: error: procedure fact is never used + 15 | proc fact(n: I64): I64; (* calling itself doesn't count *) + | ^^^^ +test/err/Unused.raz:21:14: error: parameter a is never used + 21 | proc helper*(a, _b: Used; var r: I64); + | ^ +help: if it must be there, call it _a +test/err/Unused.raz:22:5: error: variable x is assigned but never read + 22 | var x, y: I64; t: [4]I64; + | ^ +raz: 7 errors diff --git a/test/err/Unused.raz b/test/err/Unused.raz new file mode 100644 index 0000000..dc88b5a --- /dev/null +++ b/test/err/Unused.raz @@ -0,0 +1,40 @@ +module Unused; +(* What is never used is warned of, and -Werror makes it an error *) +import Out, Sys; + +const + N = 3; M* = 4; _K = 5; + +type + Color = (red, green); + Used = I64; + +var + g, h, seen: I64; + +proc fact(n: I64): I64; (* calling itself doesn't count *) +begin + if n = 0 then return 1; end; + return n * fact(n - 1); +end; + +proc helper*(a, _b: Used; var r: I64); +var x, y: I64; t: [4]I64; +begin + x := 1; + y := 2; + y := y + 1; + t[0] := 1; + r := 0; +end; + +proc main*; +var i: I64; +begin + g := 1; + seen := h; + for i := 0 to 2 do end; + Out.int(seen); +end; + +end Unused. diff --git a/test/err/mods/Rec.linux-x86_64.raz b/test/err/mods/Rec.linux-x86_64.raz index 63611c0..dc10269 100644 --- a/test/err/mods/Rec.linux-x86_64.raz +++ b/test/err/mods/Rec.linux-x86_64.raz @@ -1,4 +1,4 @@ module Rec; type R* = record a*: I64; b: I64; end; -proc f*(r: ^R); begin end; +proc f*(_r: ^R); begin end; end Rec.