raz / commit b1f5815f

commit
b1f5815f57cab990612222274b665aa20363bf8e
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
caca71d3
Notes and help: declared here, did you mean, slips from other languages

Objects keep where their names are declared (TObj.pos), for notes:
"the first one is here" for a name declared twice, "the signature is
here" for a wrong count of args, a fwd mismatch and a generic's proc,
"declared here, without a *" for what isn't exported. main's checks
point at main. Notes and help show only with a shown error; quiet
moves to diag, and scan's Fail does the recovery jump.

Did you mean: sym's Closest, by edit distance ignoring case, over the
scopes in reach, a module's exports, a record's fields. A name not
declared that is a module's file gets "import X"; elif gets elsif.

Slips: scan's Slip reports !=, !, ==, &&, || and reads on as the right
symbol, not while re-skipping after an error; help for x = 1 as a
statement and { for then/do. Tests for each in test/err.

Code: 5,545 -> 5,664 lines.

patch · log

48 files changed, +460 -93

CLAUDE.md modified +2 -1

@@ -57,7 +57,8 @@
5757 ravite (vim's). What they needed of the system went into `Sys` (report
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
60-the library. New work starts only on the owner's word. Keep
60+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
6162 `doc/compiler.md`'s table of lines and its routine names true when the
6263 compiler changes. Left for later at the owner's word: a rewrite of
6364 var parameters.

PLAN.md (history) modified +1 -1

@@ -249,7 +249,7 @@
249249 (`scan.pas`, `parse.pas` in two halves, `gen.pas`, the rest),
250250 against a list of messages and their tests the main model writes
251251 first; *main* reviews the wording as a whole.
252-- [ ] 24. Notes and help. Objects remember where they are declared:
252+- [x] 24. Notes and help. Objects remember where they are declared:
253253 "declared here", "the first one is here", "the signature is
254254 here". The checks on `main` in `raz.pas` point at
255255 it, so that every error has a place (the fuzzer finds them). Did you mean: the closest name by edit distance in the

doc/compiler.md (history) modified +26 -15

@@ -8,15 +8,15 @@
88
99 | File | Lines | Code | What |
1010 |---|---|---|---|
11-| `src/diag.pas` | 260 | 187 | Messages: positions, source excerpts, colour, counts |
12-| `src/scan.pas` | 659 | 529 | Symbols, literals, comments, positions |
13-| `src/sym.pas` | 526 | 437 | Types, objects, scopes, layout |
11+| `src/diag.pas` | 267 | 191 | Messages: positions, source excerpts, colour, counts |
12+| `src/scan.pas` | 687 | 553 | Symbols, literals, comments, positions |
13+| `src/sym.pas` | 578 | 479 | Types, objects, scopes, layout |
1414 | `src/x64.pas` | 682 | 548 | Code buffer, chunks, fixups, line notes, instruction encoder |
15-| `src/gen.pas` | 1,512 | 1,318 | Items: loading, storing, copying, frames, calls |
16-| `src/parse.pas` | 2,094 | 1,908 | Declarations, statements, expressions, built-ins, recovery |
15+| `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 |
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` | 219 | 172 | The command line, the entry points |
19+| `src/raz.pas` | 220 | 173 | 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.
@@ -111,7 +111,10 @@
111111 Every message the compiler prints is made here. A position, `TPos`, is
112112 a file and a stretch of bytes in it; `Error`, `Warning` and `Note` show
113113 it as `file:line:column`, then the line of source with the stretch
114-underlined, and `Help` adds a line of advice. The line and column are
114+underlined, and `Help` adds a line of advice. Notes and help are shown
115+only with an error that was: not one at the place of the last, and
116+not one under `quiet`, which the parser sets when an error follows
117+from another (see parse.pas). The line and column are
115118 worked out only when a message is printed (`Locate`, `Chars`), so
116119 positions cost nothing while compiling. `AddFile` keeps every source
117120 file the scanner opens, so a note can show a line of any of them.
@@ -146,13 +149,16 @@
146149 through `Mark`, at the current symbol, `MarkAt`, at a position, or
147150 `MarkHelp`, which adds a line of help; each reports the error
148151 (`diag.Error`) and jumps to `recovery`, the parser's place to go on
149-from (see parse.pas). A message names what it found: `Found` describes
152+from (see parse.pas), through `Fail`. An error with notes is reported
153+with `Error` and `Note`, then `Fail`. A message names what it found: `Found` describes
150154 the current symbol and `SymText` spells an operator or reserved word,
151155 so that the parser's `Expect` and `Expected` say `expected ";", found
152156 "end"`. Errors in the text itself stop the
153157 compiler (`MarkBytes`, `LexError`): past a string left open, the
154-symbols can't be trusted. There is no
155-recovery: the first error ends the compilation. `SaveScan` and `RestoreScan` keep
158+symbols can't be trusted. A slip from another language, such as `!=`
159+for `#`, is reported by `Slip`, which reads on as if the right symbol
160+were written; not while the parser is `skipping` what it read once
161+before an error. `SaveScan` and `RestoreScan` keep
156162 the scanner's state while an imported module is compiled.
157163
158164 ## sym.pas: types, objects and scopes
@@ -168,7 +174,8 @@
168174 the C rules. `obj` is the declaration that named the type, if any.
169175
170176 `TObj` is anything a name can stand for: a constant, type, variable,
171-procedure, module, field, variant case or built-in (`cls`). Where it
177+procedure, module, field, variant case or built-in (`cls`), and `pos`
178+is where its name is declared, for notes. Where it
172179 lives is decided here too: a module variable's chunk, a local's frame
173180 offset in `val`, a procedure's chunk.
174181
@@ -177,7 +184,9 @@
177184 sit in one open-addressed hash table, keyed by scope and name: `Find`
178185 looks in one scope, `Lookup` in each open scope from the innermost out.
179186 A lookup costs the same however big a program grows, which matters at
180-a million lines a second.
187+a million lines a second. After an error, `Closest` looks through the
188+whole table for the name in reach spelled most like one not found
189+(`Distance`), for "did you mean".
181190
182191 `Same` and `Alike` decide whether two types are the same: one
183192 declaration for named types, built alike otherwise. `Fingerprint`
@@ -329,9 +338,11 @@
329338 blocks. A symbol at the start of a line ends the skip: by the usual
330339 layout it starts the next declaration, so the statement gives up its
331340 procedure (`GiveUp`), and `SkipProc` reads to the procedure's
332-`end Name;`. A name not declared is declared where it is used, with
333-the type `tPoison` (`Poison`), as are the names of a declaration that
334-had an error; a construct that uses poison sets `quiet`, and its errors
341+`end Name;`. A name not declared is reported by `NotDeclared`, with
342+what it may have meant: a module to import (`ModuleFile`) or a name
343+spelled alike. It is then declared where it is used, with the type
344+`tPoison` (`Poison`), as are the names of a declaration that had an
345+error; a construct that uses poison sets `quiet`, and its errors
335346 aren't reported, since they follow from one that was. Nothing breaks
336347 for the half-made code: once there is an error, no executable is
337348 written.

src/diag.pas modified +10 -3

@@ -32,6 +32,9 @@
3232 var
3333 errors, warnings: longint;
3434 werror: boolean; { -Werror: a warning counts as an error }
35+ { The construct being read uses a name already reported as not
36+ declared: its errors follow from that one, and aren't shown. }
37+ quiet: boolean;
3538
3639 function AddFile(const path: shortstring; buf: PChar; len: longint): longint;
3740 function PathOf(f: longint): shortstring;
@@ -63,6 +66,7 @@
6366 colour, colourKnown: boolean;
6467 cwd: shortstring; { the working directory and a /, or '' if unknown }
6568 lastError: TPos; { where the last error was }
69+ shown: boolean; { whether it was shown: its notes and help are only then }
6670
6771 { Paths are shown from the working directory where they are under it,
6872 so messages read the same wherever the compiler or its library is. }
@@ -204,7 +208,8 @@
204208 begin
205209 { a second error at one place follows from the first: when a symbol
206210 ends a construct with an error, the one around it may stop there too }
207- if (errors > 0) and (p.f = lastError.f) and (p.a = lastError.a) then exit;
211+ shown := not quiet and not ((errors > 0) and (p.f = lastError.f) and (p.a = lastError.a));
212+ if not shown then exit;
208213 lastError := p;
209214 Show(p, 'error', Red, msg);
210215 inc(errors);
@@ -219,18 +224,20 @@
219224 if werror then Error(p, msg)
220225 else begin
221226 Show(p, 'warning', Yellow, msg);
227+ shown := true;
222228 inc(warnings);
223229 end;
224230 end;
225231
232+{ Notes and help follow an error or a warning, and are shown with it }
226233 procedure Note(const p: TPos; const msg: shortstring);
227234 begin
228- Show(p, 'note', Cyan, msg);
235+ if shown then Show(p, 'note', Cyan, msg);
229236 end;
230237
231238 procedure Help(const msg: shortstring);
232239 begin
233- writeln(StdErr, Paint(Green, 'help:'), ' ', msg);
240+ if shown then writeln(StdErr, Paint(Green, 'help:'), ' ', msg);
234241 end;
235242
236243 { An error with no place in the source, such as a file that can't be

src/gen.pas modified +11 -8

@@ -1115,6 +1115,15 @@
11151115 c.n := 0;
11161116 end;
11171117
1118+{ Too many arguments or too few, at p }
1119+procedure WrongCount(var c: TCall; const p: TPos; const what: shortstring);
1120+begin
1121+ if c.obj = nil then MarkAt(p, what);
1122+ Error(p, what + ': ' + NameOf(c.obj^.name) + ' takes ' + IntStr(c.sig^.len));
1123+ if c.obj^.module <> nil then Note(c.obj^.pos, 'the signature is here');
1124+ Fail;
1125+end;
1126+
11181127 procedure PassArg(var c: TCall; var a: TItem);
11191128 var p: PObj; s: int64;
11201129 begin
@@ -1124,10 +1133,7 @@
11241133 { past the parameters of a C procedure that ends in ...: a string
11251134 goes as a C string, an integer constant as an I64, a real
11261135 constant as an F64; C takes no F32 there }
1127- if not c.sig^.variadic then begin
1128- if c.obj = nil then MarkAt(a.pos, 'too many arguments');
1129- MarkAt(a.pos, 'too many arguments: ' + NameOf(c.obj^.name) + ' takes ' + IntStr(c.sig^.len));
1130- end;
1136+ if not c.sig^.variadic then WrongCount(c, a.pos, 'too many arguments');
11311137 if a.mode = mStr then Coerce(a, tPtrU8)
11321138 else if a.typ^.form = fConst then Coerce(a, tI64)
11331139 else if a.typ = tRConst then Coerce(a, tReal)
@@ -1166,10 +1172,7 @@
11661172 res: PType; i, ni, nf, k, pad: longint; ret: int64;
11671173 onStack: array[0..63] of boolean;
11681174 begin
1169- if c.param <> nil then begin
1170- if c.obj = nil then Mark('too few arguments');
1171- Mark('too few arguments: ' + NameOf(c.obj^.name) + ' takes ' + IntStr(c.sig^.len));
1172- end;
1175+ if c.param <> nil then WrongCount(c, TokPos, 'too few arguments');
11731176 res := c.sig^.base;
11741177 ret := 0;
11751178 ni := 0; nf := 0;

src/parse.pas modified +101 -44

@@ -85,6 +85,8 @@
8585
8686 procedure Expect(s: TSym);
8787 begin
88+ if (tok = sLbrace) and (s in [sThen, sDo]) then
89+ MarkHelp(MissingPos, 'expected ' + SymText(s) + ', found ' + Found, 'a block is written ' + SymText(s) + ' ... end');
8890 if tok <> s then Expected(SymText(s));
8991 Next;
9092 end;
@@ -94,10 +96,12 @@
9496 Name := Intern(@s[1], length(s));
9597 end;
9698
97-procedure IdentDef(var n: longint; var exp: boolean);
99+{ A name being declared, and whether it is exported; at is the name }
100+procedure IdentDef(var n: longint; var exp: boolean; var at: TPos);
98101 begin
99102 if tok <> sIdent then Expected('a name');
100103 n := id;
104+ at := TokPos;
101105 Next;
102106 exp := false;
103107 if tok = sTimes then begin
@@ -162,6 +166,7 @@
162166 begin
163167 recovery := r.outer;
164168 quiet := r.quiet;
169+ skipping := false;
165170 end;
166171
167172 { After an error: the state as it was at the start of r's construct,
@@ -169,6 +174,7 @@
169174 procedure Restore(var r: TRecover);
170175 begin
171176 RestoreScan(r.scan);
177+ skipping := true;
172178 CutScopes(r.scopes); depth := r.depth; numDefers := r.numDefers;
173179 curLoop := r.loop; curResult := r.result;
174180 deferring := r.deferring; directDefer := r.directDefer;
@@ -247,6 +253,25 @@
247253 ConstExpr := ConstValue(x);
248254 end;
249255
256+{ Help after a name that isn't found: o, the closest name in reach }
257+procedure DidYouMean(o: PObj);
258+begin
259+ if o <> nil then Help('did you mean ' + NameOf(o^.name) + '?');
260+end;
261+
262+{ Where module n is found, if it is: dir and the file in it }
263+function ModuleFile(n: longint; var dir, f: shortstring): boolean; forward;
264+
265+{ Reports name n at p as not declared, with what it may have meant }
266+procedure NotDeclared(const p: TPos; n: longint);
267+var dir, f: shortstring;
268+begin
269+ Error(p, NameOf(n) + ' isn''t declared');
270+ if ModuleFile(n, dir, f) then Help(NameOf(n) + ' is a module: import ' + NameOf(n))
271+ else if (NameOf(n) = 'elif') or (NameOf(n) = 'elseif') then Help('raz writes elsif')
272+ else DidYouMean(Closest(n, -1));
273+end;
274+
250275 function QualIdent: PObj;
251276 var o: PObj; m: PModule;
252277 begin
@@ -255,7 +280,8 @@
255280 if o = nil then begin
256281 Poison(id);
257282 quiet := false;
258- Mark(NameOf(id) + ' isn''t declared');
283+ NotDeclared(TokPos, id);
284+ Fail;
259285 end;
260286 if o^.typ = tPoison then quiet := true;
261287 Next;
@@ -264,12 +290,35 @@
264290 if tok <> sIdent then Expected('a name');
265291 m := o^.module;
266292 o := Find(m^.scope, id);
267- if (o = nil) or not o^.exported then Mark(NameOf(id) + ' isn''t exported by ' + NameOf(m^.name));
293+ if (o = nil) or not o^.exported then begin
294+ Error(TokPos, NameOf(id) + ' isn''t exported by ' + NameOf(m^.name));
295+ if o <> nil then Note(o^.pos, NameOf(id) + ' is declared here, without a *')
296+ else DidYouMean(Closest(id, m^.scope));
297+ Fail;
298+ end;
268299 Next;
269300 end;
270301 QualIdent := o;
271302 end;
272303
304+{ The field of record type t named by the current symbol }
305+function FieldOf(t: PType): PObj;
306+var f: PObj;
307+begin
308+ f := Find(t^.scope, id);
309+ if f = nil then begin
310+ Error(TokPos, TypeName(t) + ' has no field ' + NameOf(id));
311+ DidYouMean(Closest(id, t^.scope));
312+ Fail;
313+ end;
314+ if not f^.exported and (t^.module <> curModule) then begin
315+ Error(TokPos, 'field ' + NameOf(id) + ' of ' + TypeName(t) + ' isn''t exported');
316+ Note(f^.pos, NameOf(id) + ' is declared here, without a *');
317+ Fail;
318+ end;
319+ FieldOf := f;
320+end;
321+
273322 function NewPtr(base: PType; vol: boolean): PType;
274323 var t: PType;
275324 begin
@@ -284,7 +333,8 @@
284333 function RecordType: PType;
285334 var
286335 t, ft: PType; f, last: PObj; names: array[0..63] of longint;
287- exps: array[0..63] of boolean; n, i: longint; off, a, maxA: int64;
336+ exps: array[0..63] of boolean; poss: array[0..63] of TPos;
337+ n, i: longint; off, a, maxA: int64;
288338 begin
289339 t := NewType(fRecord, 0, 1);
290340 if tok = sPacked then begin t^.packd := true; Next end;
@@ -295,7 +345,7 @@
295345 n := 0;
296346 repeat
297347 if n > High(names) then Mark('more than ' + IntStr(High(names) + 1) + ' names in one declaration');
298- IdentDef(names[n], exps[n]);
348+ IdentDef(names[n], exps[n], poss[n]);
299349 inc(n);
300350 if tok <> sComma then break;
301351 Next;
@@ -307,6 +357,7 @@
307357 off := AlignUp(off, a);
308358 f := NewObj(oField, names[i], ft);
309359 f^.exported := exps[i];
360+ f^.pos := poss[i];
310361 f^.val := off;
311362 Insert(f, t^.scope);
312363 if last = nil then t^.fields := f else last^.next := f;
@@ -778,10 +829,7 @@
778829 Next;
779830 if (x.mode <> mVar) or (x.typ^.form <> fRecord) then MarkAt(x.pos, 'expected a record, found ' + What(x));
780831 if tok <> sIdent then Expected('a field');
781- f := Find(x.typ^.scope, id);
782- if f = nil then Mark(TypeName(x.typ) + ' has no field ' + NameOf(id));
783- if not f^.exported and (x.typ^.module <> curModule) then
784- Mark('field ' + NameOf(id) + ' of ' + TypeName(x.typ) + ' isn''t exported');
832+ f := FieldOf(x.typ);
785833 Next;
786834 Field(x, f);
787835 called := false;
@@ -885,10 +933,7 @@
885933 if tok <> sRbrace then
886934 repeat
887935 if tok <> sIdent then Expected('a field');
888- f := Find(t^.scope, id);
889- if f = nil then Mark(TypeName(t) + ' has no field ' + NameOf(id));
890- if not f^.exported and (t^.module <> curModule) then
891- Mark('field ' + NameOf(id) + ' of ' + TypeName(t) + ' isn''t exported');
936+ f := FieldOf(t);
892937 for i := 0 to n - 1 do if seen[i] = id then Mark('field ' + NameOf(id) + ' is given twice');
893938 if n <= High(seen) then begin seen[n] := id; inc(n) end;
894939 Next;
@@ -1131,7 +1176,7 @@
11311176 Next;
11321177 if tok <> sIdent then Expected('a name');
11331178 o := Lookup(id);
1134- if o = nil then Mark(NameOf(id) + ' isn''t declared');
1179+ if o = nil then begin NotDeclared(TokPos, id); Fail end;
11351180 if (o^.cls <> oVar) or not (o^.typ^.form in [fInt, fEnum]) then
11361181 if o^.cls = oVar then
11371182 Mark('a for loop needs an integer or enumeration variable, found ' + TypeName(o^.typ))
@@ -1346,7 +1391,9 @@
13461391 if (x.mode = mProc) or ((x.mode in [mVar, mReg]) and (x.typ^.form = fProc)) then begin
13471392 BeginCall(c, x);
13481393 EndCall(c, x);
1349- end else MarkAt(x.pos, Subject(x, first) + ' isn''t a statement');
1394+ end else if tok = sEql then
1395+ MarkHelp(x.pos, Subject(x, first) + ' isn''t a statement', 'assignment is written :=')
1396+ else MarkAt(x.pos, Subject(x, first) + ' isn''t a statement');
13501397 end;
13511398 end;
13521399 sIf: IfStatement;
@@ -1518,18 +1565,21 @@
15181565 begin
15191566 line := CurLine;
15201567 Next;
1521- at := TokPos;
1522- IdentDef(n, exp);
1523- at := SpanFrom(at);
1568+ IdentDef(n, exp, at);
15241569 sig := Signature;
15251570 Expect(sSemicolon);
15261571 p := Find(TopScope, n);
15271572 if (p <> nil) and (p^.cls = oProc) and p^.fwd then begin
1528- if not Same(p^.typ, sig) then MarkAt(at, NameOf(n) + ' doesn''t have the signature it was declared forward with');
1573+ if not Same(p^.typ, sig) then begin
1574+ Error(at, NameOf(n) + ' doesn''t have the signature it was declared forward with');
1575+ Note(p^.pos, 'the signature is here');
1576+ Fail;
1577+ end;
15291578 if tok = sForward then Mark(NameOf(n) + ' is declared forward twice');
15301579 p^.exported := p^.exported or exp;
15311580 end else begin
15321581 p := NewObj(oProc, n, sig);
1582+ p^.pos := at;
15331583 p^.exported := exp;
15341584 if (curModule^.name = nameRt) and not checkMode and (n = nameFail) then p^.chunk := rtFail
15351585 else if (curModule^.name = nameRt) and not checkMode and (n = nameEq) then p^.chunk := rtEq
@@ -1564,10 +1614,8 @@
15641614 curModule^.usesC := true;
15651615 if tok = sProc then begin
15661616 Next;
1567- at := TokPos;
1568- IdentDef(n, exp);
1617+ IdentDef(n, exp, at);
15691618 WillDeclare(n);
1570- at := SpanFrom(at);
15711619 inExtern := true;
15721620 t := Signature;
15731621 inExtern := false;
@@ -1582,7 +1630,7 @@
15821630 end else begin
15831631 if tok <> sVar then Expected('"proc" or "var"');
15841632 Next;
1585- IdentDef(n, exp);
1633+ IdentDef(n, exp, at);
15861634 WillDeclare(n);
15871635 Expect(sColon);
15881636 declExported := exp;
@@ -1590,6 +1638,7 @@
15901638 declExported := false;
15911639 o := NewObj(oVar, n, t);
15921640 end;
1641+ o^.pos := at;
15931642 o^.exported := exp;
15941643 o^.ext := true;
15951644 o^.chunk := ExternChunk(n);
@@ -1597,9 +1646,9 @@
15971646 end;
15981647
15991648 procedure ConstDecl(top: boolean);
1600-var n: longint; exp: boolean; x: TItem; o: PObj; t: PType; start: TPos;
1649+var n: longint; exp: boolean; x: TItem; o: PObj; t: PType; start, at: TPos;
16011650 begin
1602- IdentDef(n, exp);
1651+ IdentDef(n, exp, at);
16031652 WillDeclare(n);
16041653 t := nil;
16051654 if tok = sColon then begin
@@ -1611,6 +1660,7 @@
16111660 Expect(sEql);
16121661 Expression(x, nil);
16131662 o := NewObj(oConst, n, x.typ);
1663+ o^.pos := at;
16141664 o^.exported := exp and top;
16151665 if t = tError then begin
16161666 o^.typ := tError;
@@ -1622,15 +1672,16 @@
16221672 end;
16231673
16241674 procedure TypeDecl(top: boolean);
1625-var n: longint; exp: boolean; o: PObj; t: PType;
1675+var n: longint; exp: boolean; o: PObj; t: PType; at: TPos;
16261676 begin
1627- IdentDef(n, exp);
1677+ IdentDef(n, exp, at);
16281678 WillDeclare(n);
16291679 Expect(sEql);
16301680 declExported := exp and top;
16311681 inTypes := true;
16321682 t := ParseType;
16331683 o := NewObj(oType, n, t);
1684+ o^.pos := at;
16341685 o^.exported := exp and top;
16351686 if t^.obj = nil then t^.obj := o;
16361687 Declare(o);
@@ -1641,11 +1692,12 @@
16411692 var
16421693 i, k: longint; o: PObj; t: PType;
16431694 names: array[0..63] of longint; exps: array[0..63] of boolean;
1695+ poss: array[0..63] of TPos;
16441696 begin
16451697 k := 0;
16461698 repeat
16471699 if k > High(names) then Mark('more than ' + IntStr(High(names) + 1) + ' names in one declaration');
1648- IdentDef(names[k], exps[k]);
1700+ IdentDef(names[k], exps[k], poss[k]);
16491701 WillDeclare(names[k]);
16501702 inc(k);
16511703 if tok <> sComma then break;
@@ -1657,6 +1709,7 @@
16571709 declExported := false;
16581710 for i := 0 to k - 1 do begin
16591711 o := NewObj(oVar, names[i], t);
1712+ o^.pos := poss[i];
16601713 o^.exported := exps[i] and top;
16611714 o^.isVar := false;
16621715 if top then begin
@@ -1741,7 +1794,7 @@
17411794 for i := 0 to numFwd - 1 do begin
17421795 o := Lookup(fwdTypes[i]^.fwd);
17431796 if (o = nil) or (o^.cls <> oType) then begin
1744- Error(fwdPos[i], NameOf(fwdTypes[i]^.fwd) + ' isn''t declared');
1797+ NotDeclared(fwdPos[i], fwdTypes[i]^.fwd);
17451798 fwdTypes[i]^.base := tPoison;
17461799 end else fwdTypes[i]^.base := o^.typ;
17471800 fwdTypes[i]^.fwd := -1;
@@ -1830,7 +1883,7 @@
18301883 if a = nil then MarkAt(m^.args.pos[i], NameOf(m^.name) + ' needs a procedure for ' + NameOf(o^.name));
18311884 if not Same(a^.typ, sig) then begin
18321885 Error(m^.args.pos[i], NameOf(a^.name) + ' doesn''t have the signature of ' + NameOf(o^.name));
1833- Note(at, NameOf(o^.name) + ' is declared here');
1886+ Note(at, 'the signature is here');
18341887 Finish;
18351888 end;
18361889 o^.typ := a^.typ; o^.chunk := a^.chunk; o^.isCode := a^.isCode; o^.ext := a^.ext;
@@ -2029,29 +2082,33 @@
20292082 CompareIface(m, CompileFile(dir + '/' + others[i], n, args, true));
20302083 end;
20312084
2032-function ImportModule(name: longint; const args: TArgs): PModule;
2085+function ModuleFile(n: longint; var dir, f: shortstring): boolean;
20332086 const Suffixes: array[0..3] of string[16] = ('.' + Target, '.' + TargetOS, '.' + TargetArch, '');
2034-var m: PModule; i, j: longint; dir, f: shortstring;
2087+var i, j: longint;
20352088 begin
2036- m := FindModule(name, args);
2037- if m <> nil then exit(m);
2038- for i := 0 to numPending - 1 do
2039- if IsModule(pending[i], name, args) then MarkAt(args.at, NameOf(name) + ' imports itself');
20402089 for i := -1 to numInc do begin
20412090 if i = -1 then dir := mainDir
20422091 else if i = numInc then dir := libDir
20432092 else dir := incDirs[i];
20442093 for j := 0 to 3 do begin
2045- f := NameOf(name) + Suffixes[j] + '.raz';
2046- if Exists(dir + '/' + f) then begin
2047- m := CompileFile(dir + '/' + f, name, args, false);
2048- CheckSiblings(dir, f, name, m, args);
2049- exit(m);
2050- end;
2094+ f := NameOf(n) + Suffixes[j] + '.raz';
2095+ if Exists(dir + '/' + f) then exit(true);
20512096 end;
20522097 end;
2053- MarkAt(args.at, 'can''t find module ' + NameOf(name));
2054- ImportModule := nil;
2098+ ModuleFile := false;
2099+end;
2100+
2101+function ImportModule(name: longint; const args: TArgs): PModule;
2102+var m: PModule; i: longint; dir, f: shortstring;
2103+begin
2104+ m := FindModule(name, args);
2105+ if m <> nil then exit(m);
2106+ for i := 0 to numPending - 1 do
2107+ if IsModule(pending[i], name, args) then MarkAt(args.at, NameOf(name) + ' imports itself');
2108+ if not ModuleFile(name, dir, f) then MarkAt(args.at, 'can''t find module ' + NameOf(name));
2109+ m := CompileFile(dir + '/' + f, name, args, false);
2110+ CheckSiblings(dir, f, name, m, args);
2111+ ImportModule := m;
20552112 end;
20562113
20572114 function CompileMain(const path: shortstring): PModule;

src/raz.pas modified +4 -3

@@ -152,9 +152,10 @@
152152 main := Find(m^.scope, Intern('main', 4));
153153 hasResult := false;
154154 if main <> nil then begin
155- if (main^.cls <> oProc) or not main^.exported then Fatal('main must be an exported procedure');
156- if (main^.typ^.len <> 0) or ((main^.typ^.base <> nil) and (main^.typ^.base <> tI64)) then
157- Fatal('main must be proc main* or proc main*: I64');
155+ if (main^.cls <> oProc) or not main^.exported then Error(main^.pos, 'main must be an exported procedure')
156+ else if (main^.typ^.len <> 0) or ((main^.typ^.base <> nil) and (main^.typ^.base <> tI64)) then
157+ Error(main^.pos, 'main must be proc main* or proc main*: I64');
158+ Finish;
158159 hasResult := main^.typ^.base <> nil;
159160 end;
160161

src/scan.pas modified +40 -12

@@ -71,6 +71,7 @@
7171 procedure Mark(const msg: shortstring);
7272 procedure MarkAt(const p: TPos; const msg: shortstring);
7373 procedure MarkHelp(const p: TPos; const msg, hint: shortstring);
74+procedure Fail;
7475 function AtLineStart: boolean;
7576 function SymText(s: TSym): shortstring;
7677 function Found: shortstring;
@@ -79,9 +80,9 @@
7980 { Where the parser goes on after an error: the innermost statement or
8081 declaration being read. nil stops the compiler at the first error. }
8182 recovery: ^jmp_buf;
82- { The construct being read uses a name already reported as not
83- declared: its errors follow from that one, and aren't reported. }
84- quiet: boolean;
83+ { The parser is skipping what it has read once already, after an
84+ error, so slips in it aren't reported again. }
85+ skipping: boolean;
8586 procedure SaveScan(var st: TScanState);
8687 procedure RestoreScan(const st: TScanState);
8788 function TokPos: TPos;
@@ -237,21 +238,26 @@
237238 MarkAt(TokPos, msg);
238239 end;
239240
240-{ An error in the parser's construct at p: reported, then the parser
241- goes on from the recovery point. }
242-procedure MarkAt(const p: TPos; const msg: shortstring);
241+{ After an error in the parser's construct, reported with its notes
242+ and help: the parser goes on from the recovery point. }
243+procedure Fail;
243244 begin
244- if not quiet then Error(p, msg);
245245 if recovery = nil then Finish;
246246 longjmp(recovery^, 1);
247+end;
248+
249+procedure MarkAt(const p: TPos; const msg: shortstring);
250+begin
251+ Error(p, msg);
252+ Fail;
247253 end;
248254
249255 { MarkAt, with a line of help after the message. }
250256 procedure MarkHelp(const p: TPos; const msg, hint: shortstring);
251257 begin
252- if not quiet then begin Error(p, msg); Help(hint) end;
253- if recovery = nil then Finish;
254- longjmp(recovery^, 1);
258+ Error(p, msg);
259+ Help(hint);
260+ Fail;
255261 end;
256262
257263 { An error in the text at bytes a to b of the file being read, which
@@ -260,6 +266,7 @@
260266 var p: TPos;
261267 begin
262268 p.f := cur.f; p.a := a; p.b := b;
269+ quiet := false;
263270 Error(p, msg);
264271 Finish;
265272 end;
@@ -269,6 +276,17 @@
269276 MarkBytes(cur.tokPos, cur.pos, msg);
270277 end;
271278
279+{ The n characters at the scanner are how another language writes t:
280+ an error, but reading goes on as if t were written. }
281+procedure Slip(n: longint; t: TSym; const msg: shortstring);
282+var p: TPos;
283+begin
284+ p.f := cur.f; p.a := cur.pos; p.b := cur.pos + n;
285+ if not skipping then Error(p, msg);
286+ inc(cur.pos, n);
287+ tok := t;
288+end;
289+
272290 { How an operator or reserved word is written, quoted, for messages. }
273291 function SymText(s: TSym): shortstring;
274292 begin
@@ -597,7 +615,12 @@
597615 '-': begin inc(cur.pos); tok := sMinus end;
598616 '*': begin inc(cur.pos); tok := sTimes end;
599617 '/': begin inc(cur.pos); tok := sSlash end;
600- '=': begin inc(cur.pos); tok := sEql end;
618+ '=':
619+ if cur.buf[cur.pos + 1] = '=' then Slip(2, sEql, 'comparing is written =, not ==')
620+ else begin inc(cur.pos); tok := sEql end;
621+ '&':
622+ if cur.buf[cur.pos + 1] = '&' then Slip(2, sAnd, '"and" is written and, not &&')
623+ else MarkBytes(cur.pos, cur.pos + 1, 'unexpected character "&"');
601624 '#': begin inc(cur.pos); tok := sNeq end;
602625 '<': begin
603626 inc(cur.pos);
@@ -631,7 +654,12 @@
631654 '{': begin inc(cur.pos); tok := sLbrace end;
632655 '}': begin inc(cur.pos); tok := sRbrace end;
633656 '^': begin inc(cur.pos); tok := sArrow end;
634- '|': begin inc(cur.pos); tok := sBar end;
657+ '|':
658+ if cur.buf[cur.pos + 1] = '|' then Slip(2, sOr, '"or" is written or, not ||')
659+ else begin inc(cur.pos); tok := sBar end;
660+ '!':
661+ if cur.buf[cur.pos + 1] = '=' then Slip(2, sNeq, '"not equal" is written #, not !=')
662+ else Slip(1, sNot, '"not" is written not, not !');
635663 #0: begin
636664 if cur.pos < cur.len then MarkBytes(cur.pos, cur.pos + 1, 'NUL byte in the text');
637665 tok := sEof;

src/sym.pas modified +54 -2

@@ -58,6 +58,7 @@
5858 typ: PType;
5959 next: PObj; { the next in its list: scope, fields, parameters }
6060 scope: longint; { where it is declared }
61+ pos: TPos; { where its name is declared, for messages }
6162 val: int64; { oConst: value; oBuiltin: which; oCase: tag;
6263 oField: offset; oVar: frame offset }
6364 chunk: longint; { global oVar, oProc, string oConst: its chunk }
@@ -140,6 +141,7 @@
140141 procedure Insert(obj: PObj; s: longint);
141142 function Find(s, name: longint): PObj;
142143 function Lookup(name: longint): PObj;
144+function Closest(name, s: longint): PObj;
143145
144146 function AlignUp(x, a: int64): int64;
145147 function Same(a, b: PType): boolean;
@@ -151,6 +153,8 @@
151153 function Fingerprint(o: PObj): qword;
152154
153155 implementation
156+
157+uses math;
154158
155159 type
156160 PObjTab = ^TObjTab;
@@ -186,6 +190,7 @@
186190 o^.typ := typ;
187191 o^.chunk := -1;
188192 o^.module := curModule;
193+ o^.pos := TokPos;
189194 NewObj := o;
190195 end;
191196
@@ -270,8 +275,11 @@
270275 i := Slot(s, obj^.name);
271276 o := hashTab^[i];
272277 while o <> nil do begin
273- if (o^.scope = s) and (o^.name = obj^.name) then
274- Mark(NameOf(obj^.name) + ' is declared twice');
278+ if (o^.scope = s) and (o^.name = obj^.name) then begin
279+ Error(obj^.pos, NameOf(obj^.name) + ' is declared twice');
280+ Note(o^.pos, 'the first one is here');
281+ Fail;
282+ end;
275283 i := (i + 1) and hashMask;
276284 o := hashTab^[i];
277285 end;
@@ -302,6 +310,50 @@
302310 if o <> nil then exit(o);
303311 end;
304312 Lookup := nil;
313+end;
314+
315+{ How far apart two names are: the edits, a character put in, taken out,
316+ changed or swapped with the next, that make one the other, ignoring
317+ case. }
318+function Distance(const a, b: shortstring): longint;
319+var d: array[0..MaxIdent + 1, 0..MaxIdent + 1] of longint; i, j, c: longint;
320+begin
321+ for i := 0 to length(a) do d[i, 0] := i;
322+ for j := 0 to length(b) do d[0, j] := j;
323+ for i := 1 to length(a) do
324+ for j := 1 to length(b) do begin
325+ c := ord(UpCase(a[i]) <> UpCase(b[j]));
326+ d[i, j] := Min(Min(d[i - 1, j] + 1, d[i, j - 1] + 1), d[i - 1, j - 1] + c);
327+ if (i > 1) and (j > 1) and (UpCase(a[i]) = UpCase(b[j - 1]))
328+ and (UpCase(a[i - 1]) = UpCase(b[j])) then
329+ d[i, j] := Min(d[i, j], d[i - 2, j - 2] + 1);
330+ end;
331+ Distance := d[length(a), length(b)];
332+end;
333+
334+{ The name spelled most like name, for "did you mean": in scope s, if
335+ it can be reached from here, or in the scopes in reach if s < 0; nil
336+ if none is within an edit for every three characters. Only after an
337+ error, so it looks at every object. }
338+function Closest(name, s: longint): PObj;
339+var i, j, d, best: longint; o: PObj; n: shortstring; reach: boolean;
340+begin
341+ n := NameOf(name);
342+ best := length(n) div 3 + 1;
343+ Closest := nil;
344+ for i := 0 to hashMask do begin
345+ o := hashTab^[i];
346+ if (o = nil) or (o^.name = name) or (o^.name < 0) or (o^.typ = tPoison) then continue;
347+ if s >= 0 then reach := (o^.scope = s) and (o^.exported or (o^.module = curModule))
348+ else begin
349+ reach := false;
350+ for j := 0 to depth - 1 do reach := reach or (o^.scope = scopes[j]);
351+ end;
352+ if reach then begin
353+ d := Distance(n, NameOf(o^.name));
354+ if d < best then begin best := d; Closest := o end;
355+ end;
356+ end;
305357 end;
306358
307359 { Types }

test/err/AtMany.err modified +3 -0

@@ -1,4 +1,7 @@
11 test/err/AtMany.raz:7:16: error: too many arguments: Id takes 1
22 7 | x := Id(1, 2 * 3);
33 | ^^^^^
4+test/err/AtMany.raz:2:6: note: the signature is here
5+ 2 | proc Id(a: I64): I64;
6+ | ^^
47 raz: 1 error

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

@@ -1,7 +1,7 @@
11 test/err/BadProc.raz:2:33: error: cmp doesn't have the signature of hash
22 2 | import Str, M := Map([]U8, I64, Str.cmp, Str.eq);
33 | ^^^^^^^
4-lib/Map.raz:4:18: note: hash is declared here
4+lib/Map.raz:4:18: note: the signature is here
55 4 | module Map(K, V; hash: proc(k: K): U64; eq: proc(a, b: K): BOOL);
66 | ^^^^
77 raz: 1 error

test/err/DeclLitNotExported.err (history) modified +3 -0

@@ -1,4 +1,7 @@
11 test/err/DeclLitNotExported.raz:6:11: error: field extra of Plat.Info isn't exported
22 6 | i := {extra: 1};
33 | ^^^^^
4+test/run/mods/Plat.linux-x86_64.raz:3:33: note: extra is declared here, without a *
5+ 3 | type Info* = record kind*: I64; extra: I64; end;
6+ | ^^^^^
47 raz: 1 error

test/err/DeclNotExported.err modified +3 -0

@@ -1,4 +1,7 @@
11 test/err/DeclNotExported.raz:6:21: error: hidden isn't exported by DeclHidden
22 6 | n := DeclHidden.hidden;
33 | ^^^^^^
4+test/err/mods/DeclHidden.raz:3:7: note: hidden is declared here, without a *
5+ 3 | const hidden = 2;
6+ | ^^^^^^
47 raz: 1 error

test/err/Field.err (history) modified +3 -0

@@ -1,4 +1,7 @@
11 test/err/Field.raz:6:7: error: field extra of Plat.Info isn't exported
22 6 | i.extra := 1;
33 | ^^^^^
4+test/run/mods/Plat.linux-x86_64.raz:3:33: note: extra is declared here, without a *
5+ 3 | type Info* = record kind*: I64; extra: I64; end;
6+ | ^^^^^
47 raz: 1 error

test/err/GenTooFew.err modified +3 -0

@@ -1,4 +1,7 @@
11 test/err/GenTooFew.raz:6:14: error: too few arguments: Id takes 1
22 6 | x := Id();
33 | ^
4+test/err/GenTooFew.raz:2:6: note: the signature is here
5+ 2 | proc Id(a: I64): I64; begin return a; end;
6+ | ^^
47 raz: 1 error

test/err/NoteBuiltin.err added +5 -0

@@ -0,0 +1,5 @@
1+test/err/NoteBuiltin.raz:5:10: error: len isn't declared
2+ 5 | x := len(y);
3+ | ^^^
4+help: did you mean LEN?
5+raz: 1 error

test/err/NoteBuiltin.raz added +7 -0

@@ -0,0 +1,7 @@
1+module NoteBuiltin;
2+proc main*;
3+var x, y: I64;
4+begin
5+ x := len(y);
6+end;
7+end NoteBuiltin.

test/err/NoteExport.err added +5 -0

@@ -0,0 +1,5 @@
1+test/err/NoteExport.raz:6:9: error: Int isn't exported by Out
2+ 6 | Out.Int(x);
3+ | ^^^
4+help: did you mean int?
5+raz: 1 error

test/err/NoteExport.raz added +8 -0

@@ -0,0 +1,8 @@
1+module NoteExport;
2+import Out;
3+proc main*;
4+var x, y: I64;
5+begin
6+ Out.Int(x);
7+end;
8+end NoteExport.

test/err/NoteField.err added +5 -0

@@ -0,0 +1,5 @@
1+test/err/NoteField.raz:6:7: error: P has no field cuont
2+ 6 | p.cuont := 1;
3+ | ^^^^^
4+help: did you mean count?
5+raz: 1 error

test/err/NoteField.raz added +8 -0

@@ -0,0 +1,8 @@
1+module NoteField;
2+type P = record count: I64; end;
3+proc main*;
4+var p: P;
5+begin
6+ p.cuont := 1;
7+end;
8+end NoteField.

test/err/NoteImport.err added +5 -0

@@ -0,0 +1,5 @@
1+test/err/NoteImport.raz:5:5: error: Fmt isn't declared
2+ 5 | Fmt.print(x);
3+ | ^^^
4+help: Fmt is a module: import Fmt
5+raz: 1 error

test/err/NoteImport.raz added +7 -0

@@ -0,0 +1,7 @@
1+module NoteImport;
2+proc main*;
3+var x, y: I64;
4+begin
5+ Fmt.print(x);
6+end;
7+end NoteImport.

test/err/NoteLocal.err added +5 -0

@@ -0,0 +1,5 @@
1+test/err/NoteLocal.raz:6:5: error: cuont isn't declared
2+ 6 | cuont := 1;
3+ | ^^^^^
4+help: did you mean count?
5+raz: 1 error

test/err/NoteLocal.raz added +8 -0

@@ -0,0 +1,8 @@
1+module NoteLocal;
2+proc main*;
3+var x, y, count: I64;
4+begin
5+
6+ cuont := 1;
7+end;
8+end NoteLocal.

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

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

test/err/ScanTwice.err modified +5 -2

@@ -1,4 +1,7 @@
1-test/err/ScanTwice.raz:4:11: error: x is declared twice
1+test/err/ScanTwice.raz:4:5: error: x is declared twice
22 4 | x: I64;
3- | ^
3+ | ^
4+test/err/ScanTwice.raz:3:5: note: the first one is here
5+ 3 | var x: I64;
6+ | ^
47 raz: 1 error

test/err/SlipAnd.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/SlipAnd.raz:5:16: error: "and" is written and, not &&
2+ 5 | if (x = 1) && (y = 2) then x := 2; end;
3+ | ^^
4+raz: 1 error

test/err/SlipAnd.raz added +7 -0

@@ -0,0 +1,7 @@
1+module SlipAnd;
2+proc main*;
3+var x, y: I64;
4+begin
5+ if (x = 1) && (y = 2) then x := 2; end;
6+end;
7+end SlipAnd.

test/err/SlipAssign.err added +5 -0

@@ -0,0 +1,5 @@
1+test/err/SlipAssign.raz:5:5: error: x isn't a statement
2+ 5 | x = 1;
3+ | ^
4+help: assignment is written :=
5+raz: 1 error

test/err/SlipAssign.raz added +7 -0

@@ -0,0 +1,7 @@
1+module SlipAssign;
2+proc main*;
3+var x, y: I64;
4+begin
5+ x = 1;
6+end;
7+end SlipAssign.

test/err/SlipBrace.err added +5 -0

@@ -0,0 +1,5 @@
1+test/err/SlipBrace.raz:5:14: error: expected "then", found "{"
2+ 5 | if x = 1 { x := 2 }
3+ | ^
4+help: a block is written "then" ... end
5+raz: 1 error

test/err/SlipBrace.raz added +7 -0

@@ -0,0 +1,7 @@
1+module SlipBrace;
2+proc main*;
3+var x, y: I64;
4+begin
5+ if x = 1 { x := 2 }
6+end;
7+end SlipBrace.

test/err/SlipDo.err added +5 -0

@@ -0,0 +1,5 @@
1+test/err/SlipDo.raz:5:17: error: expected "do", found "{"
2+ 5 | while x < 3 { x := x + 1 }
3+ | ^
4+help: a block is written "do" ... end
5+raz: 1 error

test/err/SlipDo.raz added +7 -0

@@ -0,0 +1,7 @@
1+module SlipDo;
2+proc main*;
3+var x, y: I64;
4+begin
5+ while x < 3 { x := x + 1 }
6+end;
7+end SlipDo.

test/err/SlipElif.err added +5 -0

@@ -0,0 +1,5 @@
1+test/err/SlipElif.raz:5:27: error: elif isn't declared
2+ 5 | if x = 1 then x := 2; elif x = 3 then x := 4; end;
3+ | ^^^^
4+help: raz writes elsif
5+raz: 1 error

test/err/SlipElif.raz added +7 -0

@@ -0,0 +1,7 @@
1+module SlipElif;
2+proc main*;
3+var x, y: I64;
4+begin
5+ if x = 1 then x := 2; elif x = 3 then x := 4; end;
6+end;
7+end SlipElif.

test/err/SlipEql.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/SlipEql.raz:5:10: error: comparing is written =, not ==
2+ 5 | if x == 1 then x := 2; end;
3+ | ^^
4+raz: 1 error

test/err/SlipEql.raz added +7 -0

@@ -0,0 +1,7 @@
1+module SlipEql;
2+proc main*;
3+var x, y: I64;
4+begin
5+ if x == 1 then x := 2; end;
6+end;
7+end SlipEql.

test/err/SlipMany.err added +10 -0

@@ -0,0 +1,10 @@
1+test/err/SlipMany.raz:5:10: error: "not equal" is written #, not !=
2+ 5 | if x != 1 && z then x := y; end;
3+ | ^^
4+test/err/SlipMany.raz:5:15: error: "and" is written and, not &&
5+ 5 | if x != 1 && z then x := y; end;
6+ | ^^
7+test/err/SlipMany.raz:5:18: error: z isn't declared
8+ 5 | if x != 1 && z then x := y; end;
9+ | ^
10+raz: 3 errors

test/err/SlipMany.raz added +7 -0

@@ -0,0 +1,7 @@
1+module SlipMany;
2+proc main*;
3+var x, y: I64;
4+begin
5+ if x != 1 && z then x := y; end;
6+end;
7+end SlipMany.

test/err/SlipNeq.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/SlipNeq.raz:5:10: error: "not equal" is written #, not !=
2+ 5 | if x != 1 then x := 2; end;
3+ | ^^
4+raz: 1 error

test/err/SlipNeq.raz added +7 -0

@@ -0,0 +1,7 @@
1+module SlipNeq;
2+proc main*;
3+var x, y: I64;
4+begin
5+ if x != 1 then x := 2; end;
6+end;
7+end SlipNeq.

test/err/SlipNot.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/SlipNot.raz:5:8: error: "not" is written not, not !
2+ 5 | if ! (x = 1) then x := 2; end;
3+ | ^
4+raz: 1 error

test/err/SlipNot.raz added +7 -0

@@ -0,0 +1,7 @@
1+module SlipNot;
2+proc main*;
3+var x, y: I64;
4+begin
5+ if ! (x = 1) then x := 2; end;
6+end;
7+end SlipNot.

test/err/SlipOr.err added +4 -0

@@ -0,0 +1,4 @@
1+test/err/SlipOr.raz:5:16: error: "or" is written or, not ||
2+ 5 | if (x = 1) || (y = 2) then x := 2; end;
3+ | ^^
4+raz: 1 error

test/err/SlipOr.raz added +7 -0

@@ -0,0 +1,7 @@
1+module SlipOr;
2+proc main*;
3+var x, y: I64;
4+begin
5+ if (x = 1) || (y = 2) then x := 2; end;
6+end;
7+end SlipOr.

test/err/StmtSigForward.err modified +3 -0

@@ -1,6 +1,9 @@
11 test/err/StmtSigForward.raz:3:6: error: f doesn't have the signature it was declared forward with
22 3 | proc f(a: BOOL); begin end;
33 | ^
4+test/err/StmtSigForward.raz:2:6: note: the signature is here
5+ 2 | proc f(a: I64); forward;
6+ | ^
47 test/err/StmtSigForward.raz:4:19: error: f is declared forward but never defined
58 4 | end StmtSigForward.
69 | ^