From ce8052e05453737a530fa1238b5b00a4c676d660 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Mon, 12 Oct 2026 11:09:14 +0100 Subject: [PATCH] Diagnostics: say more of what went wrong A missing end: an end left of its statement's line is noted, and a procedure closed by the module's end says so; "else if" gets help toward elsif. A type mismatch in an argument notes the parameter it goes to. Procedure types print their signature; a procedure used as a value says it returns nothing, or how to call it. + on strings, p.x through a pointer, s.len, assigning a constant, 'ab' and Begin in the wrong case each say what to write. can't read says why; can't find module says where it looked. Long source lines are cut around the place. Rt's trap report folds a recursion's repeated calls into one line with a count. --- diff --git a/lib/Rt.raz b/lib/Rt.raz index 79a7781..ef33a6c 100644 --- a/lib/Rt.raz +++ b/lib/Rt.raz @@ -273,37 +273,64 @@ end; end; +(* Says that n more calls are as the one before, if there are any; + the lines it takes *) +proc more(n: INT): INT; +begin + if n = 0 then return 0; end; + put(" and "); + putInt(n); + put(" more the same"); + say; + return 1; +end; + (* Says the calls under way, a line each, from the one at address ip whose frame is at bp: where each is, and its variables, unless vars - is false for the first. At most 20; a frame that isn't the - program's ends them. *) + is false for the first. At most 20 lines; a frame that isn't the + program's ends them. Calls of one procedure from one place, as in a + recursion that overflowed the stack, are told once, and counted. *) proc calls(ip, bp: UINT; vars: BOOL); -var p: ^Proc; l: ^Local; i, n: INT; q: ^UINT; +var p, last: ^Proc; l: ^Local; i, n, same: INT; q: ^UINT; lastIp: UINT; begin - for n := 1 to 20 do + n := 0; + same := 0; + last := nil; + lastIp := 0; + while n < 20 do p := procAt(ip); - if p = nil then return; end; - put(" in "); - putStr(names() + INT(p^.name)); - put(" at "); - where(ip); - l := ^Local(^U8(places + 5) + 16 * places[0] + 20 * places[3]) + INT(p^.first); - if not vars or (p^.count = 0) then DEC(lineLen, 2); end; (* where's ": " *) - for i := 0 to INT(p^.count) - 1 do - if vars then - if i > 0 then put(", "); end; - putStr(names() + INT(l[i].name)); - put(" = "); - putValue(bp, l + i); + if p = nil then break; end; + if (p = last) and (ip = lastIp) then + INC(same); + else + n := n + more(same); + same := 0; + last := p; + lastIp := ip; + put(" in "); + putStr(names() + INT(p^.name)); + put(" at "); + where(ip); + l := ^Local(^U8(places + 5) + 16 * places[0] + 20 * places[3]) + INT(p^.first); + if not vars or (p^.count = 0) then DEC(lineLen, 2); end; (* where's ": " *) + for i := 0 to INT(p^.count) - 1 do + if vars then + if i > 0 then put(", "); end; + putStr(names() + INT(l[i].name)); + put(" = "); + putValue(bp, l + i); + end; end; + say; + INC(n); + vars := true; end; - say; - vars := true; q := ^UINT(bp); - if (bp & 7 # 0) or (q[0] <= bp) then return; end; + if (bp & 7 # 0) or (q[0] <= bp) then break; end; ip := q[1] - 1; (* the call, by its return address *) bp := q[0]; end; + more(same); end; (* Says on standard error the calls under way, from the one that calls diff --git a/src/diag.pas b/src/diag.pas index 0dbd882..92b5706 100644 --- a/src/diag.pas +++ b/src/diag.pas @@ -168,8 +168,12 @@ { "file:line:col: kind: msg", then the line with p underlined. A tab before p is copied into the underline, so that the two line up whatever the terminal makes of tabs. } +{ A long line is shown cut to this many bytes around the place, its + cut ends marked ... } +const ShownBytes = 100; + procedure Show(const p: TPos; const kind, kindColour, msg: shortstring); -var line, start, stop, i, n: longint; buf: PChar; num, gutter: shortstring; +var line, start, stop, lo, hi, i, n: longint; buf: PChar; num, gutter: shortstring; begin Locate(p, line, start); buf := files[p.f].buf; @@ -181,14 +185,24 @@ num := IntStr(line); while length(num) < 5 do num := ' ' + num; gutter := Paint(Blue, num + ' |'); + lo := start; hi := stop; + if hi - lo > ShownBytes then begin + if p.a - lo > ShownBytes div 2 then lo := p.a - ShownBytes div 2; + while (byte(buf[lo]) and $C0) = $80 do inc(lo); + if hi - lo > ShownBytes then hi := lo + ShownBytes; + while (hi < stop) and ((byte(buf[hi]) and $C0) = $80) do inc(hi); + end; write(StdErr, gutter, ' '); - for i := start to stop - 1 do write(StdErr, buf[i]); + if lo > start then write(StdErr, '...'); + for i := lo to hi - 1 do write(StdErr, buf[i]); + if hi < stop then write(StdErr, '...'); writeln(StdErr); write(StdErr, Paint(Blue, ' |'), ' '); - for i := start to p.a - 1 do + if lo > start then write(StdErr, ' '); + for i := lo to p.a - 1 do if buf[i] = #9 then write(StdErr, #9) else if (byte(buf[i]) and $C0) <> $80 then write(StdErr, ' '); - if p.b < stop then n := Chars(buf, p.a, p.b) else n := Chars(buf, p.a, stop); + if p.b < hi then n := Chars(buf, p.a, p.b) else n := Chars(buf, p.a, hi); if n < 1 then n := 1; writeln(StdErr, Paint(kindColour, StringOfChar('^', n))); end; diff --git a/src/item.pas b/src/item.pas index 5ef578b..2dc163c 100644 --- a/src/item.pas +++ b/src/item.pas @@ -411,6 +411,20 @@ if x.ro then MarkAt(x.pos, Source(x.pos) + ' is ' + NameOf(x.obj^.module^.name) + '''s, and can''t be changed outside it'); end; +var + passing: PObj; { the parameter the argument at passingAt goes to } + passingAt: TPos; + +{ An error in x's type; if x is an argument, a note at the parameter + it goes to. } +procedure Mismatch(const x: TItem; const msg: shortstring); +begin + Error(x.pos, msg); + if (passing <> nil) and (x.pos.f = passingAt.f) and (x.pos.a = passingAt.a) and (x.pos.b = passingAt.b) then + Note(passing^.pos, 'it goes to ' + NameOf(passing^.name) + ', declared here'); + Fail; +end; + procedure Coerce(var x: TItem; t: PType); var s: PType; tmp: int64; begin @@ -426,7 +440,7 @@ CopyTo(FrameAdr(tmp), x.val); if t^.len > x.val then ZeroVar(FrameAdr(tmp + x.val), t^.len - x.val); TempItem(x, t, tmp); - end else MarkAt(x.pos, 'can''t use a string as ' + TypeName(t)); + end else Mismatch(x, 'can''t use a string as ' + TypeName(t)); exit; end; if x.mode in [mType, mBuiltin, mNone, mCase] then NotValue(x); @@ -447,8 +461,12 @@ if x.odd then MarkAt(x.pos, 'can''t make a slice of a field of a packed record'); Address(x); SliceOf(x, t, s^.len); - end else - MarkAt(x.pos, 'can''t use ' + TypeName(s) + ' as ' + TypeName(t)); + end else if (x.mode = mProc) and (t^.form <> fProc) and (s^.base = nil) then + MarkAt(x.pos, Source(x.pos) + ' is a procedure, and returns nothing') + else if (x.mode = mProc) and (t^.form <> fProc) then + MarkHelp(x.pos, 'can''t use ' + TypeName(s) + ' as ' + TypeName(t), 'to call it, write ' + Source(x.pos) + '()') + else + Mismatch(x, 'can''t use ' + TypeName(s) + ' as ' + TypeName(t)); end; { Coerce where the types must be the same, as in a for loop, INC and @@ -663,6 +681,8 @@ SeqSlice(x) else if (op = sPlus) and (x.mode = mStr) then { two string constants to be joined: nothing to compute } + else if (op = sPlus) and IsSeq(x.typ) then + MarkHelp(x.pos, '+ doesn''t join ' + What(x), 'strings are joined in a Buf: Buf.str(b, s)') else if x.mode in [mType, mBuiltin, mNone, mCase, mStr] then NotValue(x) else if x.mode <> mConst then @@ -1070,11 +1090,13 @@ exit; end; c.isF[c.n] := (p^.typ^.form = fReal) and not p^.isVar; + passing := p; + passingAt := a.pos; if p^.isVar then begin NotReadOnly(a); if (a.mode <> mVar) or not a.isVar then MarkAt(a.pos, 'a var parameter needs a variable'); if a.odd then MarkAt(a.pos, 'a field of a packed record can''t be a var parameter'); - if not Same(a.typ, p^.typ) then MarkAt(a.pos, 'a var parameter needs exactly ' + TypeName(p^.typ) + ', found ' + What(a)); + if not Same(a.typ, p^.typ) then Mismatch(a, 'a var parameter needs exactly ' + TypeName(p^.typ) + ', found ' + What(a)); if a.vol then MarkAt(a.pos, 'can''t pass through a volatile pointer to a var parameter'); Address(a); s := AllocTemp(8, 8); diff --git a/src/parse.pas b/src/parse.pas index f6a7162..f8c4291 100644 --- a/src/parse.pas +++ b/src/parse.pas @@ -87,6 +87,9 @@ deferred: array[0..63] of TDeferred; numDeferred: longint; making: boolean; { reading an instance's arguments, at its first use } + stray: boolean; { an "end" in this procedure stood left of its statement's line } + strayAt: TPos; { ... the first such statement } + elseIf: boolean; { an "else if" in this procedure } useAt: TPos; { ... which is here } procedure Expression(var x: TItem; want: PType); forward; @@ -110,6 +113,29 @@ Next; end; +{ The end of a block statement at start, whose line is indented to + ind. An "end" left of that was most likely meant for a block around + the statement, which leaves the statement's own "end" missing: the + first such is kept for EndMissing. } +procedure CloseEnd(const start: TPos; ind: longint); +begin + if (tok = sEnd) and not stray and (Indent < ind) then begin + stray := true; + strayAt := start; + end; + Expect(sEnd); +end; + +{ The error of a procedure or module whose own "end" isn't where it + should be, with what CloseEnd saw } +procedure EndMissing(const p: TPos; const msg: shortstring); +begin + Error(p, msg); + if stray then Note(strayAt, 'is this statement''s "end" missing? one further left closes it'); + if elseIf then Help('raz writes elsif: "else if" begins an if that needs its own "end"'); + Fail; +end; + function Name(const s: shortstring): longint; begin Name := Intern(@s[1], length(s)); @@ -305,6 +331,7 @@ Error(p, NameOf(n) + ' isn''t declared'); if ModuleFile(n, dir, f) then Help(NameOf(n) + ' is a module: import ' + NameOf(n)) else if (NameOf(n) = 'elif') or (NameOf(n) = 'elseif') then Help('raz writes elsif') + else if Reserved(Name(LowerCase(NameOf(n)))) then Help('a reserved word is written in lower case: ' + LowerCase(NameOf(n))) else DidYouMean(Closest(n, -1)); end; @@ -824,6 +851,20 @@ end else if f <> nil then MarkAt(at, NameOf(c^.name) + ' needs its fields'); end; +{ x, before ".", has no fields; tok is what follows. Other languages + write p.f through a pointer and s.len for a length. } +procedure FieldOfWhat(const x: TItem); +var msg, f: shortstring; +begin + msg := 'expected a record, found ' + What(x); + if tok = sIdent then f := NameOf(id) else f := ''; + if (x.typ^.form = fPtr) and (x.typ^.base^.form = fRecord) then + MarkHelp(x.pos, msg, 'through a pointer, write ' + Source(x.pos) + '^.' + f) + else if (x.typ^.form in [fArray, fSlice]) and ((f = 'len') or (f = 'length') or (f = 'size') or (f = 'count')) then + MarkHelp(x.pos, msg, 'its length is LEN(' + Source(x.pos) + ')'); + MarkAt(x.pos, msg); +end; + { A designator, with any selectors and calls after it. called tells whether the last thing done was a call. } procedure Designator(var x: TItem; var called: boolean); @@ -845,7 +886,7 @@ case tok of sPeriod: begin Next; - if (x.mode <> mVar) or (x.typ^.form <> fRecord) then MarkAt(x.pos, 'expected a record, found ' + What(x)); + if (x.mode <> mVar) or (x.typ^.form <> fRecord) then FieldOfWhat(x); if tok <> sIdent then Expected('a field'); f := FieldOf(x.typ); Next; @@ -1154,7 +1195,7 @@ for i := numDefers - 1 downto base do RunDefer(defers[i]); end; -procedure IfStatement; +procedure IfStatement(const start: TPos; ind: longint); var x: TItem; L, endL: longint; begin Next; @@ -1178,13 +1219,14 @@ Jump(endL); Fix(L); Next; + if tok = sIf then elseIf := true; Statements; end else Fix(L); - Expect(sEnd); + CloseEnd(start, ind); Fix(endL); end; -procedure WhileStatement; +procedure WhileStatement(const start: TPos; ind: longint); var x: TItem; top, L: longint; lp: TLoop; old: PLoop; begin Next; @@ -1196,7 +1238,7 @@ Loop(lp, old); Statements; JumpBack(top); - Expect(sEnd); + CloseEnd(start, ind); Fix(L); Fix(lp.brk); curLoop := old; @@ -1218,7 +1260,7 @@ Fix(lp.brk); end; -procedure ForStatement; +procedure ForStatement(const start: TPos; ind: longint); var o: PObj; v, a, b, s: TItem; bslot, step: int64; top, exitL: longint; lp: TLoop; old: PLoop; @@ -1260,7 +1302,7 @@ Loop(lp, old); Statements; curLoop := old; - Expect(sEnd); + CloseEnd(start, ind); ForNext(o, bslot, step, exitL, top); Fix(exitL); Fix(lp.brk); @@ -1319,7 +1361,7 @@ Fix(L); end; -procedure MatchStatement; +procedure MatchStatement(const start: TPos; ind: longint); var x: TItem; t: PType; c, f, o: PObj; p: int64; L, endL, n: longint; seen: array[0..255] of boolean; hasElse: boolean; endAt: TPos; ls: TLabels; @@ -1383,7 +1425,7 @@ end; end; endAt := TokPos; - Expect(sEnd); + CloseEnd(start, ind); if (t^.form = fInt) and not hasElse then MarkHelp(endAt, 'a match on an integer needs an else arm', 'it may be empty: | else:'); if not hasElse then begin @@ -1409,6 +1451,8 @@ array constant, nor any part of one. } procedure Assignable(const x: TItem; n: longint); begin + if (x.mode = mConst) and (Subject(x, n) = NameOf(n)) then + MarkAt(x.pos, NameOf(n) + ' is a constant, and can''t be changed'); if (x.mode = mVar) and (x.obj <> nil) and (x.obj^.cls = oConst) then MarkAt(x.pos, NameOf(x.obj^.name) + ' is a constant, and can''t be changed'); if (x.mode <> mVar) or not x.isVar then MarkAt(x.pos, 'can''t assign to ' + Subject(x, n)); @@ -1532,11 +1576,11 @@ else MarkAt(x.pos, Subject(x, first) + ' isn''t a statement'); end else Discard(x); end; - sIf: IfStatement; - sWhile: WhileStatement; + sIf: IfStatement(start, Indent); + sWhile: WhileStatement(start, Indent); sRepeat: RepeatStatement; - sFor: ForStatement; - sMatch: MatchStatement; + sFor: ForStatement(start, Indent); + sMatch: MatchStatement(start, Indent); sReturn: begin Next; if deferring then MarkAt(SpanFrom(start), 'return can''t leave a deferred statement'); @@ -1567,7 +1611,7 @@ Jump(curLoop^.brk); end; sDefer: Defer; - else if AtLineStart then Expected('"end"') + else if AtLineStart then EndMissing(MissingPos, 'expected "end", found ' + Found) else Expected('a statement'); end; ReleaseTemps(m); @@ -1691,6 +1735,7 @@ old := curResult; curResult := sig^.base; EnterBody(p^.chunk, line); + stray := false; elseIf := false; Statements; NoteLine(CurLine, CurCol); Expect(sEnd); @@ -1762,7 +1807,8 @@ CodeBody(p, sig, at); end else if checkMode then SkipBody else Body(p, sig, line); if tok = sIdent then begin - if id <> n then Mark('expected ' + NameOf(n) + ', found ' + NameOf(id)); + if id = curModule^.name then EndMissing(TokPos, NameOf(n) + ' has no "end": this one closes the module') + else if id <> n then EndMissing(TokPos, 'expected ' + NameOf(n) + ', found ' + NameOf(id)); Next; end; end; @@ -2188,14 +2234,15 @@ st: TScanState; saved: array[0..MaxDepth - 1] of longint; d: longint; oldMod: PModule; oldCheck, oldChecks: boolean; m: PModule; lib: PLib; start: TPos; alias, mname, line, oldPath: longint; o: PObj; body: longint; iargs: TArgs; - generic: boolean; argsAt: TScanState; + generic: boolean; argsAt: TScanState; why: shortstring; begin SaveScan(st); SaveScopes(d, saved); oldMod := curModule; oldCheck := checkMode; oldPath := curFile; oldChecks := checks; checks := true; curFile := Name(path); - if not Open(path) then Fatal('can''t read ' + path); + why := Open(path); + if why <> '' then Fatal('can''t read ' + path + ': ' + why); New(m); FillChar(m^, SizeOf(TModule), 0); m^.name := n; @@ -2298,13 +2345,14 @@ deferSlot := 0; curResult := nil; EnterBody(body, line); + stray := false; elseIf := false; Statements; NoteLine(CurLine, CurCol); Expect(sEnd); EndProc(body); end; end else Expect(sEnd); - if (tok <> sIdent) or (id <> n) then Expected(NameOf(n)); + if (tok <> sIdent) or (id <> n) then EndMissing(MissingPos, 'expected ' + NameOf(n) + ', found ' + Found); Next; if tok <> sPeriod then Expected('"."'); o := m^.first; @@ -2445,7 +2493,13 @@ if m <> nil then exit(m); for i := 0 to numPending - 1 do if IsModule(pending[i], name, args) then MarkAt(args.at, NameOf(name) + ' imports itself'); - if not ModuleFile(name, dir, f) then MarkAt(args.at, 'can''t find module ' + NameOf(name)); + if not ModuleFile(name, dir, f) then begin + Error(args.at, 'can''t find module ' + NameOf(name)); + dir := ShownPath(SearchDir(-1)); + for i := 0 to numInc do dir := dir + ', ' + ShownPath(SearchDir(i)); + Help('looked for ' + NameOf(name) + '.raz in ' + dir); + Fail; + end; CheckOneModule(name, dir, f, args.at); m := CompileFile(dir + '/' + f, name, args, false); CheckSiblings(dir, f, name, m, args); diff --git a/src/scan.pas b/src/scan.pas index 3f44fd0..92c6fc4 100644 --- a/src/scan.pas +++ b/src/scan.pas @@ -65,13 +65,15 @@ function Intern(p: PChar; n: longint): longint; function NameOf(n: longint): shortstring; -function Open(const path: shortstring): boolean; +function Reserved(n: longint): boolean; +function Open(const path: shortstring): shortstring; procedure Next; procedure Mark(const msg: shortstring); procedure MarkAt(const p: TPos; const msg: shortstring); procedure MarkHelp(const p: TPos; const msg, hint: shortstring); procedure Fail; function AtLineStart: boolean; +function Indent: longint; function SymText(s: TSym): shortstring; function Found: shortstring; @@ -334,16 +336,37 @@ AtLineStart := cur.tokPos = cur.tokLineStart; end; +{ The column the current symbol's line is indented to } +function Indent: longint; +var i: longint; +begin + i := cur.tokLineStart; + while cur.buf[i] in [' ', #9] do inc(i); + Indent := i - cur.tokLineStart + 1; +end; + { Files } -function Open(const path: shortstring): boolean; +{ Name n is a reserved word } +function Reserved(n: longint): boolean; +begin + Reserved := n < NumWords; +end; + +{ Reads the file at path to scan it; '' if it can, else why not } +function Open(const path: shortstring): shortstring; var fd: cint; st: Stat; n, got, r: longint; p: shortstring; begin p := path + #0; fd := FpOpen(@p[1], O_RDONLY); - if fd < 0 then exit(false); - if FpFStat(fd, st) <> 0 then begin FpClose(fd); exit(false) end; - if (st.st_mode and S_IFMT) <> S_IFREG then begin FpClose(fd); exit(false) end; + if fd < 0 then + case FpGetErrno of + ESysENOENT: exit('there is no such file'); + ESysEACCES: exit('permission denied'); + else exit('it can''t be opened'); + end; + if FpFStat(fd, st) <> 0 then begin FpClose(fd); exit('it can''t be opened') end; + if (st.st_mode and S_IFMT) <> S_IFREG then begin FpClose(fd); exit('it isn''t a file') end; n := st.st_size; cur.buf := GetMem(n + 1); got := 0; @@ -362,7 +385,7 @@ cur.tokLine := 1; cur.tokLineStart := 0; cur.f := AddFile(path, cur.buf, n); - Open := true; + Open := ''; end; procedure SaveScan(var st: TScanState); @@ -724,7 +747,7 @@ end; procedure Next; -var c: char; start, h, v: longint; +var c: char; start, h, v, i: longint; begin cur.prevEnd := cur.pos; repeat @@ -758,7 +781,13 @@ inc(cur.pos); if cur.buf[cur.pos] = '''' then LexError('empty character'); v := LitChar(false); - if cur.buf[cur.pos] <> '''' then LexError('character not closed'); + if cur.buf[cur.pos] <> '''' then begin + { 'ab': several characters, as some languages write a string } + i := cur.pos; + while not (cur.buf[i] in ['''', #10, #0]) do inc(i); + if cur.buf[i] = '''' then MarkBytes(cur.tokPos, i + 1, 'a character is one character: the string is "' + Text(cur.tokPos + 1, i) + '"') + else LexError('character not closed'); + end; inc(cur.pos); tok := sChar; ival := v; diff --git a/src/sym.pas b/src/sym.pas index b8a2121..6e3c5ae 100644 --- a/src/sym.pas +++ b/src/sym.pas @@ -466,7 +466,19 @@ TypeName := s + ')'; end; fVariant: TypeName := 'variant'; - fProc: TypeName := 'proc'; + fProc: begin + s := 'proc('; + f := t^.fields; + while f <> nil do begin + if f^.isVar then s := s + 'var '; + s := s + TypeName(f^.typ); + f := f^.next; + if f <> nil then s := s + ', '; + end; + s := s + ')'; + if t^.base <> nil then s := s + ': ' + TypeName(t^.base); + TypeName := s; + end; else TypeName := '?'; end; end; diff --git a/test/err/DeclManyElements.err b/test/err/DeclManyElements.err index 9c16170..7afca46 100644 --- a/test/err/DeclManyElements.err +++ b/test/err/DeclManyElements.err @@ -1,4 +1,4 @@ test/err/DeclManyElements.raz:5:2059: error: more than 1024 elements - 5 | a := [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; - | ^ + 5 | ...0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; + | ^ raz: 1 error diff --git a/test/err/DeclManyNames.err b/test/err/DeclManyNames.err index 681f5d3..a81ec53 100644 --- a/test/err/DeclManyNames.err +++ b/test/err/DeclManyNames.err @@ -1,4 +1,4 @@ test/err/DeclManyNames.raz:2:327: error: more than 64 names in one declaration - 2 | type R = record a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, a51, a52, a53, a54, a55, a56, a57, a58, a59, a60, a61, a62, a63, a64: I64 end; - | ^^^ + 2 | ...a54, a55, a56, a57, a58, a59, a60, a61, a62, a63, a64: I64 end; + | ^^^ raz: 1 error diff --git a/test/err/ExprJoinStrings.err b/test/err/ExprJoinStrings.err new file mode 100644 index 0000000..ab07717 --- /dev/null +++ b/test/err/ExprJoinStrings.err @@ -0,0 +1,5 @@ +test/err/ExprJoinStrings.raz:7:13: error: + doesn't join []U8 + 7 | Out.str(s + "def"); + | ^ +help: strings are joined in a Buf: Buf.str(b, s) +raz: 1 error diff --git a/test/err/ExprJoinStrings.raz b/test/err/ExprJoinStrings.raz new file mode 100644 index 0000000..98e3f33 --- /dev/null +++ b/test/err/ExprJoinStrings.raz @@ -0,0 +1,9 @@ +module ExprJoinStrings; +import Out; +proc main*; +var s: []U8; +begin + s := "abc"; + Out.str(s + "def"); +end; +end ExprJoinStrings. diff --git a/test/err/ExprNoField.err b/test/err/ExprNoField.err new file mode 100644 index 0000000..f810657 --- /dev/null +++ b/test/err/ExprNoField.err @@ -0,0 +1,9 @@ +test/err/ExprNoField.raz:7:10: error: expected a record, found ^R + 7 | n := p.x; + | ^ +help: through a pointer, write p^.x +test/err/ExprNoField.raz:8:10: error: expected a record, found []U8 + 8 | n := s.len; + | ^ +help: its length is LEN(s) +raz: 2 errors diff --git a/test/err/ExprNoField.raz b/test/err/ExprNoField.raz new file mode 100644 index 0000000..119e48c --- /dev/null +++ b/test/err/ExprNoField.raz @@ -0,0 +1,10 @@ +module ExprNoField; +type R = record x: I64; end; +proc main*; +var r: R; p: ^R; s: []U8; n: I64; +begin + p := ADR(r); + n := p.x; + n := s.len; +end; +end ExprNoField. diff --git a/test/err/ExprProcValue.err b/test/err/ExprProcValue.err new file mode 100644 index 0000000..4605086 --- /dev/null +++ b/test/err/ExprProcValue.err @@ -0,0 +1,8 @@ +test/err/ExprProcValue.raz:10:10: error: Out.ln is a procedure, and returns nothing + 10 | a := Out.ln; + | ^^^^^^ +test/err/ExprProcValue.raz:11:10: error: can't use proc(): (I64, I64) as I64 + 11 | a := pair; + | ^^^^ +help: to call it, write pair() +raz: 2 errors diff --git a/test/err/ExprProcValue.raz b/test/err/ExprProcValue.raz new file mode 100644 index 0000000..d478cbb --- /dev/null +++ b/test/err/ExprProcValue.raz @@ -0,0 +1,13 @@ +module ExprProcValue; +import Out; +proc pair: (I64, I64); +begin + return 1, 2; +end; +proc main*; +var a: I64; +begin + a := Out.ln; + a := pair; +end; +end ExprProcValue. diff --git a/test/err/NameKeywordCase.err b/test/err/NameKeywordCase.err new file mode 100644 index 0000000..cbd2e3e --- /dev/null +++ b/test/err/NameKeywordCase.err @@ -0,0 +1,9 @@ +test/err/NameKeywordCase.raz:7:5: error: Begin isn't declared + 7 | Begin + | ^^^^^ +help: a reserved word is written in lower case: begin +test/err/NameKeywordCase.raz:9:1: error: End isn't declared + 9 | End; + | ^^^ +help: a reserved word is written in lower case: end +raz: 2 errors diff --git a/test/err/NameKeywordCase.raz b/test/err/NameKeywordCase.raz new file mode 100644 index 0000000..31606fe --- /dev/null +++ b/test/err/NameKeywordCase.raz @@ -0,0 +1,10 @@ +module NameKeywordCase; +import Out; +proc main*; +var a: I64; +begin + a := 1; + Begin + Out.int(a); +End; +end NameKeywordCase. diff --git a/test/err/StmtElseIf.err b/test/err/StmtElseIf.err new file mode 100644 index 0000000..0021eac --- /dev/null +++ b/test/err/StmtElseIf.err @@ -0,0 +1,8 @@ +test/err/StmtElseIf.raz:12:5: error: main has no "end": this one closes the module + 12 | end StmtElseIf. + | ^^^^^^^^^^ +test/err/StmtElseIf.raz:6:5: note: is this statement's "end" missing? one further left closes it + 6 | if x > 0 then + | ^^ +help: raz writes elsif: "else if" begins an if that needs its own "end" +raz: 1 error diff --git a/test/err/StmtElseIf.raz b/test/err/StmtElseIf.raz new file mode 100644 index 0000000..b1d8d19 --- /dev/null +++ b/test/err/StmtElseIf.raz @@ -0,0 +1,12 @@ +module StmtElseIf; +import Out; +proc main*; +var x: I64; +begin + if x > 0 then + Out.ln; + else if x < 0 then + Out.ln; + end; +end; +end StmtElseIf. diff --git a/test/err/StmtEndMissing.err b/test/err/StmtEndMissing.err new file mode 100644 index 0000000..ec96312 --- /dev/null +++ b/test/err/StmtEndMissing.err @@ -0,0 +1,7 @@ +test/err/StmtEndMissing.raz:9:5: error: main has no "end": this one closes the module + 9 | end StmtEndMissing. + | ^^^^^^^^^^^^^^ +test/err/StmtEndMissing.raz:6:5: note: is this statement's "end" missing? one further left closes it + 6 | if x > 0 then + | ^^ +raz: 1 error diff --git a/test/err/StmtEndMissing.raz b/test/err/StmtEndMissing.raz new file mode 100644 index 0000000..2c0bd8a --- /dev/null +++ b/test/err/StmtEndMissing.raz @@ -0,0 +1,9 @@ +module StmtEndMissing; +import Out; +proc main*; +var x: I64; +begin + if x > 0 then + Out.int(x); +end; +end StmtEndMissing. diff --git a/test/err/StmtManyDefers.err b/test/err/StmtManyDefers.err index 23f8221..f302bd2 100644 --- a/test/err/StmtManyDefers.err +++ b/test/err/StmtManyDefers.err @@ -1,4 +1,4 @@ test/err/StmtManyDefers.raz:9:173: error: more than 64 deferred statements in one procedure - 9 | defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; - | ^^^^^ + 9 | ...a := 1; defer a := 1; defer a := 1; defer a := 1; defer a := 1; + | ^^^^^ raz: 1 error diff --git a/test/err/StmtManyNames.err b/test/err/StmtManyNames.err index 031781a..32087cf 100644 --- a/test/err/StmtManyNames.err +++ b/test/err/StmtManyNames.err @@ -1,4 +1,4 @@ test/err/StmtManyNames.raz:2:315: error: more than 64 names in one declaration - 2 | var a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20, a21, a22, a23, a24, a25, a26, a27, a28, a29, a30, a31, a32, a33, a34, a35, a36, a37, a38, a39, a40, a41, a42, a43, a44, a45, a46, a47, a48, a49, a50, a51, a52, a53, a54, a55, a56, a57, a58, a59, a60, a61, a62, a63, a64: I64; - | ^^^ + 2 | ...a54, a55, a56, a57, a58, a59, a60, a61, a62, a63, a64: I64; + | ^^^ raz: 1 error diff --git a/test/msg/AtArgType.err b/test/msg/AtArgType.err index b1e3ce8..12b28ce 100644 --- a/test/msg/AtArgType.err +++ b/test/msg/AtArgType.err @@ -1,4 +1,7 @@ conform/err/AtArgType.raz:7:8: error: can't use BOOL as I64 7 | Id(b); | ^ +conform/err/AtArgType.raz:2:9: note: it goes to a, declared here + 2 | proc Id(a: I64): I64; + | ^ raz: 1 error diff --git a/test/msg/AtPCantAssign.err b/test/msg/AtPCantAssign.err index bfa3b85..c4a937e 100644 --- a/test/msg/AtPCantAssign.err +++ b/test/msg/AtPCantAssign.err @@ -1,4 +1,4 @@ -conform/err/AtPCantAssign.raz:7:8: error: can't assign to k +conform/err/AtPCantAssign.raz:7:8: error: k is a constant, and can't be changed 7 | a, k := two(); | ^ raz: 1 error diff --git a/test/msg/GenVarExact.err b/test/msg/GenVarExact.err index 7ea91b0..8bb8be0 100644 --- a/test/msg/GenVarExact.err +++ b/test/msg/GenVarExact.err @@ -1,4 +1,7 @@ conform/err/GenVarExact.raz:6:7: error: a var parameter needs exactly I64, found I32 6 | P(x); | ^ +conform/err/GenVarExact.raz:2:12: note: it goes to a, declared here + 2 | proc P(var a: I64); begin end; + | ^ raz: 1 error diff --git a/test/msg/ScanCharOpen.err b/test/msg/ScanCharOpen.err index cf765c2..a07b1d9 100644 --- a/test/msg/ScanCharOpen.err +++ b/test/msg/ScanCharOpen.err @@ -1,4 +1,4 @@ -conform/err/ScanCharOpen.raz:5:10: error: character not closed +conform/err/ScanCharOpen.raz:5:10: error: a character is one character: the string is "ab" 5 | c := 'ab'; - | ^^ + | ^^^^ raz: 1 error diff --git a/test/msg/StmtAssignConst.err b/test/msg/StmtAssignConst.err index e11cae3..2dd7f9c 100644 --- a/test/msg/StmtAssignConst.err +++ b/test/msg/StmtAssignConst.err @@ -1,4 +1,4 @@ -conform/err/StmtAssignConst.raz:5:5: error: can't assign to k +conform/err/StmtAssignConst.raz:5:5: error: k is a constant, and can't be changed 5 | k := 2; | ^ raz: 1 error diff --git a/test/msg/StmtNoModule.err b/test/msg/StmtNoModule.err index a0797ce..14ed781 100644 --- a/test/msg/StmtNoModule.err +++ b/test/msg/StmtNoModule.err @@ -1,4 +1,5 @@ conform/err/StmtNoModule.raz:2:8: error: can't find module Nothing 2 | import Nothing; | ^^^^^^^ +help: looked for Nothing.raz in conform/err, conform/err/mods, lib raz: 1 error diff --git a/test/run/StackOverflow.stderr b/test/run/StackOverflow.stderr index 0910336..8f6be8b 100644 --- a/test/run/StackOverflow.stderr +++ b/test/run/StackOverflow.stderr @@ -1,18 +1,5 @@ test/run/StackOverflow.raz:7:1: stopped by a stack overflow in StackOverflow.down at test/run/StackOverflow.raz:7:1 in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 14 - in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 13 - in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 12 - in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 11 - in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 10 - in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 9 - in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 8 - in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 7 - in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 6 - in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 5 - in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 4 - in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 3 - in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 2 - in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 1 - in StackOverflow.down at test/run/StackOverflow.raz:11:5: n = 0 + and 14 more the same in StackOverflow.main at test/run/StackOverflow.raz:16:5 diff --git a/test/run/ThreadOverflow.stderr b/test/run/ThreadOverflow.stderr index bf49229..0cd7fb1 100644 --- a/test/run/ThreadOverflow.stderr +++ b/test/run/ThreadOverflow.stderr @@ -1,21 +1,6 @@ test/run/ThreadOverflow.raz:6:1: stopped by a stack overflow in ThreadOverflow.down at test/run/ThreadOverflow.raz:6:1 in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1926 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1925 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1924 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1923 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1922 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1921 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1920 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1919 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1918 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1917 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1916 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1915 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1914 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1913 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1912 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1911 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1910 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1909 - in ThreadOverflow.down at test/run/ThreadOverflow.raz:10:5: n = 1908 + and 1926 more the same + in ThreadOverflow.work at test/run/ThreadOverflow.raz:15:5: _arg = nil + in Thread.run at lib/Thread.linux-x86_64.raz:78:5: arg = 0x?, t = 0x? diff --git a/test/scantest.pas b/test/scantest.pas index 7623e20..bd228f0 100644 --- a/test/scantest.pas +++ b/test/scantest.pas @@ -4,7 +4,7 @@ uses diag, scan; var i: longint; begin - if not Open(ParamStr(1)) then Fatal('no file'); + if Open(ParamStr(1)) <> '' then Fatal('no file'); repeat Next; write(LineOf(TokPos), ':', TokPos.a, ' ', ord(tok));