From 22cd3a48802e278f7e09f1577a937c63d47cddeb Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Sun, 11 Oct 2026 01:06:17 +0100 Subject: [PATCH] Errors point at the offending construct Items carry their source span; errors about an item or two operands underline it, a missing symbol goes after the one before when the next starts a new line, scanner errors underline the bad characters. An import's arguments keep positions: generic errors point at the importer, with a note at the parameter. Paths are shown from the working directory. 40 new tests in test/err/At*. --- diff --git a/PLAN.md b/PLAN.md index eee302e..e543299 100644 --- a/PLAN.md +++ b/PLAN.md @@ -220,7 +220,7 @@ `X.err` becomes the whole message, without colour, and the Makefile compares all of it. *main*; regenerating and checking the 57 `.err` files, *agent*. -- [ ] 21. Exact positions. An item and a statement remember where +- [x] 21. Exact positions. An item and a statement remember where they start, so an error points at the whole offending expression, not the symbol after it; a missing `;`, `then` or `end` points just after the symbol before it. The scanner keeps diff --git a/doc/compiler.md b/doc/compiler.md index a677721..fbaeaba 100644 --- a/doc/compiler.md +++ b/doc/compiler.md @@ -8,12 +8,12 @@ | File | Lines | Code | What | |---|---|---|---| -| `src/diag.pas` | 227 | 162 | Messages: positions, source excerpts, colour, counts | -| `src/scan.pas` | 535 | 459 | Symbols, literals, comments, positions | -| `src/sym.pas` | 508 | 422 | Types, objects, scopes, layout | +| `src/diag.pas` | 243 | 174 | Messages: positions, source excerpts, colour, counts | +| `src/scan.pas` | 584 | 495 | Symbols, literals, comments, positions | +| `src/sym.pas` | 510 | 424 | Types, objects, scopes, layout | | `src/x64.pas` | 680 | 546 | Code buffer, chunks, fixups, line notes, instruction encoder | -| `src/gen.pas` | 1,414 | 1,240 | Items: loading, storing, copying, frames, calls | -| `src/parse.pas` | 1,816 | 1,685 | Declarations, statements, expressions, built-ins | +| `src/gen.pas` | 1,421 | 1,247 | Items: loading, storing, copying, frames, calls | +| `src/parse.pas` | 1,851 | 1,720 | Declarations, statements, expressions, built-ins | | `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` | 219 | 172 | The command line, the entry points | @@ -145,8 +145,12 @@ Source is UTF-8, checked by `Utf8` wherever a byte above 127 appears: in strings, characters and comments. Anywhere else it is an error. -`TokPos` is the position of the current symbol. Errors go through -`Mark`, which reports one there (`diag.Error`) and stops. There is no +`TokPos` is the position of the current symbol, `SpanFrom` the stretch +from a saved position to the end of the symbol before the current one, +and `MissingPos` the place to say a symbol is missing: just after the +symbol before, when the current one starts a new line. Errors go +through `Mark`, at the current symbol, or `MarkAt`, at a position; each +reports the error (`diag.Error`) and stops. There is no recovery: the first error ends the compilation. `SaveScan` and `RestoreScan` keep the scanner's state while an imported module is compiled. @@ -224,6 +228,11 @@ (`bSlot`); plus `off`; - `mReg`: a value in `rax`; `mStack`: a value pushed on the stack; - `mProc`, `mType`, `mStr`, and a few more the parser needs. + +An item also carries `pos`, the stretch of source it came from, which +the parser sets as it reads an expression; an error about an item is +reported there (`MarkAt(x.pos, ...)`), and one about two operands +across both (`Join(x.pos, y.pos)`). Three routines move items towards the machine. `Value` brings a value into `rax`, loading it with the one instruction its size needs. diff --git a/src/diag.pas b/src/diag.pas index d3b10dc..fb072bd 100644 --- a/src/diag.pas +++ b/src/diag.pas @@ -36,6 +36,7 @@ function AddFile(const path: shortstring; buf: PChar; len: longint): longint; function PathOf(f: longint): shortstring; function LineOf(const p: TPos): longint; +function Join(const p, q: TPos): TPos; procedure Error(const p: TPos; const msg: shortstring); procedure Warning(const p: TPos; const msg: shortstring); procedure Note(const p: TPos; const msg: shortstring); @@ -58,14 +59,22 @@ files: ^TFile; { numFiles of them, in room for cap } numFiles, cap: longint; colour, colourKnown: boolean; + cwd: shortstring; { the working directory and a /, or '' if unknown } +{ Paths are shown from the working directory where they are under it, + so messages read the same wherever the compiler or its library is. } function AddFile(const path: shortstring; buf: PChar; len: longint): longint; +var d: array[0..255] of char; begin + if numFiles = 0 then + if FpGetcwd(@d[0], SizeOf(d)) <> nil then cwd := StrPas(@d[0]) + '/'; if numFiles = cap then begin cap := 2 * cap + 8; ReallocMem(files, cap * SizeOf(TFile)); end; - files[numFiles].path := path; + if (cwd <> '') and (copy(path, 1, length(cwd)) = cwd) then + files[numFiles].path := copy(path, length(cwd) + 1, 255) + else files[numFiles].path := path; files[numFiles].buf := buf; files[numFiles].len := len; AddFile := numFiles; @@ -167,6 +176,13 @@ if p.b < stop then n := Chars(buf, p.a, p.b) else n := Chars(buf, p.a, stop); if n < 1 then n := 1; writeln(StdErr, Paint(kindColour, StringOfChar('^', n))); +end; + +{ From the start of p to the end of q } +function Join(const p, q: TPos): TPos; +begin + Join := p; + Join.b := q.b; end; { Messages } diff --git a/src/gen.pas b/src/gen.pas index 6e73f9b..a06e20d 100644 --- a/src/gen.pas +++ b/src/gen.pas @@ -44,6 +44,7 @@ vol: boolean; { mVar: reached through ^VOLATILE } isVar: boolean; { mVar: a variable of the program, not a temporary } obj: PObj; { mProc, mBuiltin, mCase } + pos: TPos; { where it is in the source, for messages } end; TCall = record @@ -147,8 +148,11 @@ { Items } procedure MakeConst(var x: TItem; t: PType; v: int64); +var p: TPos; begin + p := x.pos; FillChar(x, SizeOf(x), 0); + x.pos := p; x.mode := mConst; x.typ := t; x.val := v; @@ -306,7 +310,7 @@ case x.mode of mConst: ConstTo(RAX, x); mVar: begin - if not IsScalar(x.typ) then Mark('not a single value'); + if not IsScalar(x.typ) then MarkAt(x.pos, 'not a single value'); m := MemOf(x, RAX); Load(RAX, m, ScalarSize(x.typ), (x.typ^.form = fInt) and x.typ^.signed); end; @@ -314,11 +318,11 @@ mStack: PopR(RAX); mProc: begin if x.obj^.isCode and (x.obj^.typ^.base <> nil) and x.obj^.typ^.base^.tuple then - Mark('a code procedure with two results can only be called'); + MarkAt(x.pos, 'a code procedure with two results can only be called'); if x.obj^.ext then Load(RAX, MemRip(x.obj^.chunk, 0), 8, false) else Lea(RAX, MemRip(x.obj^.chunk, 0)); end; - else Mark('not a value'); + else MarkAt(x.pos, 'not a value'); end; x.mode := mReg; end; @@ -331,7 +335,7 @@ m := MemOf(x, r); if (x.base <> bReg) or (x.reg <> r) or (x.off <> 0) then Lea(r, m); x.base := bReg; x.reg := r; x.off := 0; - end else Mark('not a variable'); + end else MarkAt(x.pos, 'not a variable'); end; procedure Save(var x: TItem); @@ -380,8 +384,11 @@ end; procedure TempItem(var x: TItem; t: PType; off: int64); +var p: TPos; begin + p := x.pos; FillChar(x, SizeOf(x), 0); + x.pos := p; x.mode := mVar; x.typ := t; x.base := bFrame; x.off := off; end; @@ -405,7 +412,7 @@ procedure CopyToTemp(var x: TItem); var t: int64; begin - if x.vol then Mark('can''t copy through a volatile pointer'); + if x.vol then MarkAt(x.pos, 'can''t copy through a volatile pointer'); t := AllocTemp(x.typ^.size, x.typ^.align); Address(x, RSI); Lea(RDI, Mem(RBP, t)); @@ -442,14 +449,14 @@ MovRI(RAX, 0); RepStosb; TempItem(x, t, tmp); - end else Mark('can''t use a string as ' + TypeName(t)); + end else MarkAt(x.pos, 'can''t use a string as ' + TypeName(t)); exit; end; - if x.mode in [mType, mBuiltin, mNone, mCase] then Mark('not a value'); + if x.mode in [mType, mBuiltin, mNone, mCase] then MarkAt(x.pos, 'not a value'); if Same(s, t) then exit; if (s = tRConst) and (t^.form = fReal) then RealTo(x, t) else if (s^.form = fConst) and (t^.form = fInt) then begin - if (x.mode = mConst) and not Fits(x.val, t) then Mark('constant doesn''t fit ' + TypeName(t)); + if (x.mode = mConst) and not Fits(x.val, t) then MarkAt(x.pos, 'constant doesn''t fit ' + TypeName(t)); x.typ := t; end else if (s^.form = fNil) and (t^.form in [fPtr, fProc, fError]) then x.typ := t @@ -457,11 +464,11 @@ and Same(s^.base, t^.base) then x.typ := t else if (s^.form = fArray) and (t^.form = fSlice) and Same(s^.base, t^.base) then begin - if x.vol then Mark('can''t make a slice through a volatile pointer'); + if x.vol then MarkAt(x.pos, 'can''t make a slice through a volatile pointer'); Address(x, RAX); SliceOf(x, t, s^.len); end else - Mark('can''t use ' + TypeName(s) + ' as ' + TypeName(t)); + MarkAt(x.pos, 'can''t use ' + TypeName(s) + ' as ' + TypeName(t)); end; procedure Assign(var dst, src: TItem); @@ -473,7 +480,7 @@ m := MemOf(dst, RCX); Store(m, RAX, ScalarSize(dst.typ)); end else begin - if dst.vol or src.vol then Mark('can''t copy through a volatile pointer'); + if dst.vol or src.vol then MarkAt(src.pos, 'can''t copy through a volatile pointer'); Address(src, RSI); Address(dst, RDI); Copy(dst.typ^.size); @@ -508,8 +515,8 @@ var t: PType; begin t := x.typ; - if t^.form <> fPtr then Mark('not a pointer'); - if t^.base = nil then Mark('pointer to an undeclared type'); + if t^.form <> fPtr then MarkAt(x.pos, 'not a pointer'); + if t^.base = nil then MarkAt(x.pos, 'pointer to an undeclared type'); Value(x); x.mode := mVar; x.base := bReg; x.reg := RAX; x.off := 0; x.typ := t^.base; x.vol := t^.vol; x.isVar := true; @@ -525,12 +532,12 @@ begin if x.mode = mStr then Coerce(x, tBytes); if (x.typ^.form = fPtr) and (x.typ^.base^.form = fArray) then - Mark('a pointer to an array is indexed as p^[i]'); + MarkAt(x.pos, 'a pointer to an array is indexed as p^[i]'); if x.typ^.form = fPtr then begin Value(x); PushRax; x.mode := mStack end else if (x.mode = mVar) and (x.typ^.form in [fArray, fSlice]) then Save(x) - else Mark('not an array, slice or pointer'); + else MarkAt(x.pos, 'not an array, slice or pointer'); end; procedure Index(var x, y: TItem); @@ -538,7 +545,7 @@ begin t := x.typ; s := t^.base^.size; - if not IsInt(y.typ) then Mark('an index is an integer'); + if not IsInt(y.typ) then MarkAt(y.pos, 'an index is an integer'); if t^.form = fPtr then begin Value(y); if s <> 1 then ImulI(RAX, s); @@ -547,7 +554,7 @@ x.mode := mVar; x.base := bReg; x.reg := RAX; x.off := 0; x.vol := t^.vol; x.isVar := true; end else if (t^.form = fArray) and (y.mode = mConst) then begin - if (y.val < 0) or (y.val >= t^.len) then Mark('index out of range'); + if (y.val < 0) or (y.val >= t^.len) then MarkAt(y.pos, 'index out of range'); x.off := x.off + y.val * s; if x.base = bStack then begin PopR(RAX); x.base := bReg; x.reg := RAX @@ -576,7 +583,7 @@ procedure SliceLo(var lo: TItem); begin - if not IsInt(lo.typ) then Mark('an index is an integer'); + if not IsInt(lo.typ) then MarkAt(lo.pos, 'an index is an integer'); Value(lo); PushRax; end; @@ -586,8 +593,8 @@ begin t := x.typ; s := t^.base^.size; - if not IsInt(hi.typ) then Mark('an index is an integer'); - if x.vol then Mark('can''t make a slice through a volatile pointer'); + if not IsInt(hi.typ) then MarkAt(hi.pos, 'an index is an integer'); + if x.vol then MarkAt(x.pos, 'can''t make a slice through a volatile pointer'); Value(hi); MovRR(RDX, RAX); PopR(RCX); @@ -630,7 +637,7 @@ end else if IsInt(x.typ) then begin if x.mode = mConst then x.val := Cut(-x.val, x.typ) else begin Value(x); Unary(3, RAX); Norm(x.typ) end; - end else Mark('can''t negate ' + TypeName(x.typ)); + end else MarkAt(x.pos, 'can''t negate ' + TypeName(x.typ)); end; procedure NotOp(var x: TItem); @@ -641,7 +648,7 @@ end else if IsInt(x.typ) then begin if x.mode = mConst then x.val := Cut(not x.val, x.typ) else begin Value(x); Unary(2, RAX); Norm(x.typ) end; - end else Mark('not needs BOOL or an integer'); + end else MarkAt(x.pos, 'not needs BOOL or an integer'); end; function IsStrLike(t: PType): boolean; @@ -660,7 +667,7 @@ end else begin if x.mode = mStr then begin Address(x, RAX); SliceOf(x, t, x.val) end else begin - if x.vol then Mark('can''t compare through a volatile pointer'); + if x.vol then MarkAt(x.pos, 'can''t compare through a volatile pointer'); Address(x, RAX); SliceOf(x, t, x.typ^.len) end; end; @@ -679,7 +686,7 @@ end else if (op in [sEql, sNeq]) and IsStrLike(x.typ) then StrSlice(x) else if x.mode in [mType, mBuiltin, mNone, mCase, mStr] then - Mark('not a value') + MarkAt(x.pos, 'not a value') else if x.mode <> mConst then begin Value(x); PushRax; x.mode := mStack end; @@ -694,7 +701,7 @@ Log2 := n; end; -function FoldInt(op: TSym; a, b: int64; t: PType): int64; +function FoldInt(op: TSym; a, b: int64; t: PType; const p: TPos): int64; var u: boolean; begin u := (t^.form = fInt) and not t^.signed; @@ -703,11 +710,11 @@ sMinus: FoldInt := a - b; sTimes: FoldInt := a * b; sDiv, sMod: begin - if b = 0 then Mark('division by zero'); + if b = 0 then MarkAt(p, 'division by zero'); if u then begin if op = sDiv then FoldInt := int64(qword(a) div qword(b)) else FoldInt := int64(qword(a) mod qword(b)); - end else if (b = -1) and (a = low(int64)) then Mark('division overflows') + end else if (b = -1) and (a = low(int64)) then MarkAt(p, 'division overflows') else if op = sDiv then FoldInt := a div b else FoldInt := a mod b; end; @@ -723,7 +730,7 @@ sLeq: if u then FoldInt := ord(qword(a) <= qword(b)) else FoldInt := ord(a <= b); sGtr: if u then FoldInt := ord(qword(a) > qword(b)) else FoldInt := ord(a > b); sGeq: if u then FoldInt := ord(qword(a) >= qword(b)) else FoldInt := ord(a >= b); - else Mark('bad operator'); FoldInt := 0; + else MarkAt(p, 'bad operator'); FoldInt := 0; end; end; @@ -759,10 +766,10 @@ xt, yt, t: PType; r: TItem; scale, sh: longint; isPtr, unsign, f: boolean; a, b: int64; begin xt := x.typ; yt := y.typ; - if y.mode in [mType, mBuiltin, mNone, mCase] then Mark('not a value'); + if y.mode in [mType, mBuiltin, mNone, mCase] then MarkAt(y.pos, 'not a value'); if (op in [sAnd, sOr]) and (xt^.form = fBool) then begin - if yt^.form <> fBool then Mark('and, or need two BOOLs'); + if yt^.form <> fBool then MarkAt(y.pos, 'and, or need two BOOLs'); if (x.mode = mConst) and (y.mode = mConst) then begin FixLink(L); if op = sAnd then x.val := x.val and y.val else x.val := x.val or y.val; @@ -775,7 +782,7 @@ end; if (op in [sEql, sNeq]) and IsStrLike(xt) then begin - if not IsStrLike(yt) then Mark('can''t compare a string with ' + TypeName(yt)); + if not IsStrLike(yt) then MarkAt(y.pos, 'can''t compare a string with ' + TypeName(yt)); StrSlice(y); Address(y, RSI); Address(x, RDI); @@ -792,58 +799,58 @@ { the type of the result, and the checks } t := nil; scale := 1; isPtr := false; if IsInt(xt) and IsInt(yt) then begin - if op = sSlash then Mark('/ is for reals; integers use div'); + if op = sSlash then MarkAt(Join(x.pos, y.pos), '/ is for reals; integers use div'); if op in [sShl, sShr] then begin if xt^.form = fConst then t := tConst else t := xt end else if (xt^.form = fConst) and (yt^.form = fConst) then t := tConst else if xt^.form = fConst then begin - if (x.mode = mConst) and not Fits(x.val, yt) then Mark('constant doesn''t fit ' + TypeName(yt)); + if (x.mode = mConst) and not Fits(x.val, yt) then MarkAt(x.pos, 'constant doesn''t fit ' + TypeName(yt)); t := yt end else if yt^.form = fConst then begin - if (y.mode = mConst) and not Fits(y.val, xt) then Mark('constant doesn''t fit ' + TypeName(xt)); + if (y.mode = mConst) and not Fits(y.val, xt) then MarkAt(y.pos, 'constant doesn''t fit ' + TypeName(xt)); t := xt end else if Same(xt, yt) then t := xt - else Mark('different types: ' + TypeName(xt) + ' and ' + TypeName(yt)); + else MarkAt(Join(x.pos, y.pos), 'different types: ' + TypeName(xt) + ' and ' + TypeName(yt)); end else if (xt^.form = fReal) and (yt^.form = fReal) then begin - if not (op in Rel + [sPlus, sMinus, sTimes, sSlash]) then Mark('not a real operator'); + if not (op in Rel + [sPlus, sMinus, sTimes, sSlash]) then MarkAt(Join(x.pos, y.pos), 'not a real operator'); if xt = tRConst then t := yt else if (yt = tRConst) or Same(xt, yt) then t := xt - else Mark('different types: ' + TypeName(xt) + ' and ' + TypeName(yt)); + else MarkAt(Join(x.pos, y.pos), 'different types: ' + TypeName(xt) + ' and ' + TypeName(yt)); if (x.mode = mConst) and (x.typ <> t) then RealTo(x, t); if (y.mode = mConst) and (y.typ <> t) then RealTo(y, t); end else if (xt^.form = fBool) and (yt^.form = fBool) then begin - if not (op in [sXor, sEql, sNeq]) then Mark('not a BOOL operator'); + if not (op in [sXor, sEql, sNeq]) then MarkAt(Join(x.pos, y.pos), 'not a BOOL operator'); t := tBool; end else if (xt^.form = fPtr) and IsInt(yt) and (op in [sPlus, sMinus]) then begin t := xt; scale := xt^.base^.size; isPtr := true; if y.mode = mConst then y.typ := tI64; end else if (xt^.form = fPtr) and (yt^.form = fPtr) and (op = sMinus) then begin - if not Same(xt, yt) then Mark('different pointer types'); + if not Same(xt, yt) then MarkAt(Join(x.pos, y.pos), 'different pointer types'); t := tI64; scale := xt^.base^.size; isPtr := true; end else if (xt^.form in [fPtr, fProc, fNil, fError]) and (yt^.form in [fPtr, fProc, fNil, fError]) then begin - if not (op in Rel) then Mark('not a pointer operator'); + if not (op in Rel) then MarkAt(Join(x.pos, y.pos), 'not a pointer operator'); if (xt^.form in [fProc, fError]) or (yt^.form in [fProc, fError]) then - if not (op in [sEql, sNeq]) then Mark('procedures and errors compare only with = and #'); + if not (op in [sEql, sNeq]) then MarkAt(Join(x.pos, y.pos), 'procedures and errors compare only with = and #'); if (xt^.form <> fNil) and (yt^.form <> fNil) and not Same(xt, yt) then if not ((xt^.form = fPtr) and (yt^.form = fPtr) and Same(xt^.base, yt^.base)) then - Mark('different pointer types'); + MarkAt(Join(x.pos, y.pos), 'different pointer types'); t := tU64; end else if (xt^.form = fEnum) and Same(xt, yt) then begin - if not (op in Rel) then Mark('enumerations only compare'); + if not (op in Rel) then MarkAt(Join(x.pos, y.pos), 'enumerations only compare'); t := xt; end else if (xt^.form = fSet) and Same(xt, yt) then begin - if not (op in [sPlus, sTimes, sMinus, sEql, sNeq, sLeq, sGeq]) then Mark('not a set operator'); + if not (op in [sPlus, sTimes, sMinus, sEql, sNeq, sLeq, sGeq]) then MarkAt(Join(x.pos, y.pos), 'not a set operator'); t := xt; end else if (op = sIn) and (yt^.form = fSet) and Same(xt, yt^.base) then t := yt else - Mark('can''t combine ' + TypeName(xt) + ' and ' + TypeName(yt)); + MarkAt(Join(x.pos, y.pos), 'can''t combine ' + TypeName(xt) + ' and ' + TypeName(yt)); unsign := (t^.form = fInt) and not t^.signed; { constants } if (x.mode = mConst) and (y.mode = mConst) and not isPtr then begin if t^.form = fReal then begin - if not FoldReal(op, x, y, t, r) then Mark('not a real operator'); + if not FoldReal(op, x, y, t, r) then MarkAt(Join(x.pos, y.pos), 'not a real operator'); x := r; end else if t^.form = fSet then begin a := x.val; b := y.val; @@ -857,9 +864,9 @@ else MakeConst(x, tBool, ord((a = b) = (op = sEql))); end; end else if op in Rel then - MakeConst(x, tBool, FoldInt(op, x.val, y.val, t)) + MakeConst(x, tBool, FoldInt(op, x.val, y.val, t, Join(x.pos, y.pos))) else - MakeConst(x, t, Cut(FoldInt(op, x.val, y.val, t), t)); + MakeConst(x, t, Cut(FoldInt(op, x.val, y.val, t, Join(x.pos, y.pos)), t)); exit; end; @@ -935,7 +942,7 @@ sXor: Alu(aluXor, RAX, RCX); sShl: Shift(shShl, RAX); sShr: if unsign then Shift(shShr, RAX) else Shift(shSar, RAX); - else Mark('not an operator for ' + TypeName(t)); + else MarkAt(Join(x.pos, y.pos), 'not an operator for ' + TypeName(t)); end; Norm(t); end; @@ -947,14 +954,14 @@ var s: PType; r: double; L1, L2: longint; f: boolean; begin s := x.typ; - if x.mode in [mType, mBuiltin, mNone, mCase, mStr] then Mark('can''t convert this'); + if x.mode in [mType, mBuiltin, mNone, mCase, mStr] then MarkAt(x.pos, 'can''t convert this'); if Same(s, t) then exit; if (IsInt(s) or (s^.form in [fEnum, fSet])) and (t^.form = fInt) then begin if x.mode = mConst then x.val := Cut(x.val, t) else begin Value(x); Norm(t) end; end else if IsInt(s) and (t^.form = fEnum) then begin if x.mode = mConst then begin - if (x.val < 0) or (x.val >= t^.len) then Mark('not a position of ' + TypeName(t)) + if (x.val < 0) or (x.val >= t^.len) then MarkAt(x.pos, 'not a position of ' + TypeName(t)) end else begin Value(x); CmpI(RAX, t^.len); Check(ccB) end; end else if IsInt(s) and (t^.form = fSet) then begin if x.mode = mConst then begin @@ -1009,7 +1016,7 @@ end else if (s^.form in [fPtr, fProc]) and (t^.form = fInt) then begin Value(x); Norm(t) end else - Mark('can''t convert ' + TypeName(s) + ' to ' + TypeName(t)); + MarkAt(x.pos, 'can''t convert ' + TypeName(s) + ' to ' + TypeName(t)); x.typ := t; end; @@ -1022,7 +1029,7 @@ c.code := x.obj^.isCode; c.ext := x.obj^.ext; end else begin c.code := false; c.ext := false; - if x.typ^.form <> fProc then Mark('not a procedure'); + if x.typ^.form <> fProc then MarkAt(x.pos, 'not a procedure'); c.sig := x.typ; c.chunk := -1; c.target := ToSlot(x); end; @@ -1034,17 +1041,17 @@ var p: PObj; s: int64; begin p := c.param; - if c.n > High(c.slots) then Mark('too many arguments'); + if c.n > High(c.slots) then MarkAt(a.pos, 'too many arguments'); if p = nil then begin { past the parameters of a C procedure that ends in ...: a string goes as a C string, an integer constant as an I64, a real constant as an F64; C takes no F32 there } - if not c.sig^.variadic then Mark('too many arguments'); + if not c.sig^.variadic then MarkAt(a.pos, 'too many arguments'); if a.mode = mStr then Coerce(a, tPtrU8) else if a.typ^.form = fConst then Coerce(a, tI64) else if a.typ = tRConst then Coerce(a, tReal) - else if IsF32(a.typ) then Mark('an F32 goes to ... as F64(x)') - else if not IsScalar(a.typ) then Mark('only a single value goes to ...'); + else if IsF32(a.typ) then MarkAt(a.pos, 'an F32 goes to ... as F64(x)') + else if not IsScalar(a.typ) then MarkAt(a.pos, 'only a single value goes to ...'); c.isF[c.n] := a.typ^.form = fReal; c.slots[c.n] := ToSlot(a); inc(c.n); @@ -1052,9 +1059,9 @@ end; c.isF[c.n] := (p^.typ^.form = fReal) and not p^.isVar; if p^.isVar then begin - if (a.mode <> mVar) or not a.isVar then Mark('a var parameter needs a variable'); - if not Same(a.typ, p^.typ) then Mark('a var parameter needs exactly ' + TypeName(p^.typ)); - if a.vol then Mark('can''t pass through a volatile pointer to a var parameter'); + if (a.mode <> mVar) or not a.isVar then MarkAt(a.pos, 'a var parameter needs a variable'); + if not Same(a.typ, p^.typ) then MarkAt(a.pos, 'a var parameter needs exactly ' + TypeName(p^.typ)); + if a.vol then MarkAt(a.pos, 'can''t pass through a volatile pointer to a var parameter'); Address(a, RAX); s := AllocTemp(8, 8); Store(Mem(RBP, s), RAX, 8); @@ -1161,7 +1168,7 @@ Value(a); Store(Mem(RBP, x.off + f^.val), RAX, ScalarSize(f^.typ)); end else begin - if a.vol then Mark('can''t copy through a volatile pointer'); + if a.vol then MarkAt(a.pos, 'can''t copy through a volatile pointer'); Address(a, RSI); Lea(RDI, Mem(RBP, x.off + f^.val)); Copy(f^.typ^.size); @@ -1173,7 +1180,7 @@ var p: int64; begin if x.typ^.form = fEnum then exit(ToSlot(x)); - if (x.mode <> mVar) or (x.typ^.form <> fVariant) then Mark('match needs a variant or an enumeration'); + if (x.mode <> mVar) or (x.typ^.form <> fVariant) then MarkAt(x.pos, 'match needs a variant or an enumeration'); Address(x, RAX); p := AllocTemp(8, 8); Store(Mem(RBP, p), RAX, 8); @@ -1218,7 +1225,7 @@ procedure CondJump(var x: TItem; var L: longint); begin - if x.typ^.form <> fBool then Mark('a condition is a BOOL'); + if x.typ^.form <> fBool then MarkAt(x.pos, 'a condition is a BOOL'); Value(x); TestRR(RAX, RAX); Jcc(ccE, L); @@ -1283,10 +1290,10 @@ procedure ReturnValue(var x: TItem); begin - if result = nil then Mark('this procedure returns nothing'); + if result = nil then MarkAt(x.pos, 'this procedure returns nothing'); Coerce(x, result); if IsAggregate(result) then begin - if x.vol then Mark('can''t copy through a volatile pointer'); + if x.vol then MarkAt(x.pos, 'can''t copy through a volatile pointer'); Address(x, RSI); Load(RDI, Mem(RBP, retSlot), 8, false); Copy(result^.size); @@ -1303,7 +1310,7 @@ Load(RCX, Mem(RBP, retSlot), 8, false); Store(Mem(RCX, f^.val), RAX, ScalarSize(f^.typ)); end else begin - if x.vol then Mark('can''t copy through a volatile pointer'); + if x.vol then MarkAt(x.pos, 'can''t copy through a volatile pointer'); Address(x, RSI); Load(RDI, Mem(RBP, retSlot), 8, false); Lea(RDI, Mem(RDI, f^.val)); @@ -1350,7 +1357,7 @@ function ErrorChunk(var x: TItem; module, name: longint): longint; var c: longint; p: PBytes; begin - if x.mode <> mStr then Mark('an error is made from a string'); + if x.mode <> mStr then MarkAt(x.pos, 'an error is made from a string'); p := GetMem(x.val + 8); PInt64(p)^ := x.val; Move(rodata^[chunks^[x.chunk].start], p^[8], x.val); diff --git a/src/parse.pas b/src/parse.pas index e27743a..48fe040 100644 --- a/src/parse.pas +++ b/src/parse.pas @@ -74,7 +74,7 @@ procedure Expect(s: TSym; const what: shortstring); begin - if tok <> s then Mark(what + ' expected'); + if tok <> s then MarkAt(MissingPos, what + ' expected'); Next; end; @@ -85,7 +85,7 @@ procedure IdentDef(var n: longint; var exp: boolean); begin - if tok <> sIdent then Mark('name expected'); + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); n := id; Next; exp := false; @@ -109,7 +109,7 @@ function ConstValue(var x: TItem): int64; begin - if x.mode <> mConst then Mark('constant expected'); + if x.mode <> mConst then MarkAt(x.pos, 'constant expected'); ConstValue := x.val; end; @@ -117,20 +117,20 @@ var x: TItem; begin Expression(x, nil); - if not IsInt(x.typ) then Mark('integer constant expected'); + if not IsInt(x.typ) then MarkAt(x.pos, 'integer constant expected'); ConstExpr := ConstValue(x); end; function QualIdent: PObj; var o: PObj; begin - if tok <> sIdent then Mark('name expected'); + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); o := Lookup(id); if o = nil then Mark(NameOf(id) + ' isn''t declared'); Next; if o^.cls = oModule then begin Expect(sPeriod, '.'); - if tok <> sIdent then Mark('name expected'); + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); o := Find(o^.module^.scope, id); if (o = nil) or not o^.exported then Mark(NameOf(id) + ' isn''t exported'); Next; @@ -211,7 +211,7 @@ repeat n := 0; repeat - if tok <> sIdent then Mark('name expected'); + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); f := NewObj(oField, id, nil); f^.exported := true; if lastF = nil then c^.fields := f else lastF^.next := f; @@ -293,7 +293,7 @@ if isVar then Next; first := nil; repeat - if tok <> sIdent then Mark('name expected'); + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); p := NewObj(oVar, id, nil); p^.isVar := isVar; p^.lev := 1; @@ -322,13 +322,14 @@ end; function EnumType: PType; -var t: PType; o, last: PObj; +var t: PType; o, last: PObj; start: TPos; begin + start := TokPos; t := NewType(fEnum, 1, 1); last := nil; repeat Next; - if tok <> sIdent then Mark('name expected'); + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); o := NewObj(oConst, id, t); o^.val := t^.len; o^.exported := declExported; @@ -339,14 +340,14 @@ Next; until tok <> sComma; Expect(sRparen, ')'); - if t^.len > 256 then Mark('more than 256 names'); + if t^.len > 256 then MarkAt(SpanFrom(start), 'more than 256 names'); EnumType := t; end; -function SetOf(e: PType): PType; +function SetOf(e: PType; const at: TPos): PType; var t: PType; begin - if (e^.form <> fEnum) or (e^.len > 64) then Mark('a set is of an enumeration of at most 64 names'); + if (e^.form <> fEnum) or (e^.len > 64) then MarkAt(at, 'a set is of an enumeration of at most 64 names'); t := NewType(fSet, 8, 8); if e^.len <= 8 then t^.size := 1 else if e^.len <= 16 then t^.size := 2 @@ -358,12 +359,13 @@ end; function ParseType: PType; -var t: PType; o: PObj; n: int64; vol: boolean; +var t: PType; o: PObj; n: int64; vol: boolean; start: TPos; begin + start := TokPos; case tok of sIdent: begin o := QualIdent; - if o^.cls <> oType then Mark('type expected'); + if o^.cls <> oType then MarkAt(SpanFrom(start), 'type expected'); t := o^.typ; end; sLbrak: begin @@ -373,8 +375,9 @@ t := NewType(fSlice, 16, 8); t^.base := ParseType(); end else begin + start := TokPos; n := ConstExpr; - if (n <= 0) or (n > (int64(1) shl 40)) then Mark('bad array length'); + if (n <= 0) or (n > (int64(1) shl 40)) then MarkAt(SpanFrom(start), 'bad array length'); Expect(sRbrak, ']'); t := NewType(fArray, 0, 1); t^.len := n; @@ -405,9 +408,10 @@ sSet: begin Next; Expect(sOf, 'of'); - t := SetOf(ParseType()); + start := TokPos; + t := SetOf(ParseType(), start); end; - else Mark('type expected'); + else MarkAt(MissingPos, 'type expected'); end; ParseType := t; end; @@ -437,7 +441,7 @@ for i := 0 to n - 1 do begin if i > 0 then Expect(sComma, ','); Expression(a, nil); - if not (IsScalar(a.typ) and (a.typ^.form <> fReal)) then Mark('integer or pointer expected'); + if not (IsScalar(a.typ) and (a.typ^.form <> fReal)) then MarkAt(a.pos, 'integer or pointer expected'); if a.typ^.form = fConst then Coerce(a, tI64); slots[i] := ToSlot(a); end; @@ -447,10 +451,10 @@ var p, a: TItem; t: PType; s: array[0..2] of int64; i, n: longint; begin Expression(p, nil); - if p.typ^.form <> fPtr then Mark('a pointer expected'); + if p.typ^.form <> fPtr then MarkAt(p.pos, 'a pointer expected'); t := p.typ^.base; if not (((t^.form = fInt) or ((t^.form = fPtr) and (which <> bXadd))) and (t^.size = 8)) then - Mark('an 8-byte integer or pointer expected'); + MarkAt(p.pos, 'an 8-byte integer or pointer expected'); s[0] := ToSlot(p); if which = bCas then n := 2 else n := 1; for i := 1 to n do begin @@ -481,14 +485,14 @@ var y, z: TItem; t: PType; f: PObj; s: int64; c: TCall; L: longint; begin Expression(x, nil); - if (x.mode <> mVar) or not x.isVar or (x.typ^.form <> fPtr) then Mark('NEW needs a pointer variable'); + if (x.mode <> mVar) or not x.isVar or (x.typ^.form <> fPtr) then MarkAt(x.pos, 'NEW needs a pointer variable'); t := x.typ^.base; Save(x); Expect(sComma, ','); Expression(y, nil); if (y.typ^.form <> fPtr) or (y.typ^.base^.obj = nil) or (y.typ^.base^.obj^.module = nil) or (NameOf(y.typ^.base^.obj^.name) <> 'Allocator') - or (NameOf(y.typ^.base^.obj^.module^.name) <> 'Mem') then Mark('NEW needs a ^Mem.Allocator'); + or (NameOf(y.typ^.base^.obj^.module^.name) <> 'Mem') then MarkAt(y.pos, 'NEW needs a ^Mem.Allocator'); f := Find(y.typ^.base^.scope, Name('alloc')); s := ToSlot(y); Load(RAX, Mem(RBP, s), 8, false); @@ -543,7 +547,7 @@ end; bAdr: begin Expression(y, nil); - if (y.mode <> mVar) or not y.isVar then Mark('ADR needs a variable'); + if (y.mode <> mVar) or not y.isVar then MarkAt(y.pos, 'ADR needs a variable'); t := NewPtr(y.typ, y.vol); Address(y, RAX); MakeConst(x, t, 0); @@ -558,7 +562,7 @@ Load(RAX, Mem(RAX, 8), 8, false); MakeConst(x, tI64, 0); x.mode := mReg; - end else Mark('LEN needs an array or slice'); + end else MarkAt(y.pos, 'LEN needs an array or slice'); end; bSyscall: begin n := 1; @@ -566,7 +570,7 @@ while (tok = sComma) and (n < 7) do begin Next; Expression(y, nil); - if not (IsScalar(y.typ) and (y.typ^.form <> fReal)) then Mark('integer or pointer expected'); + if not (IsScalar(y.typ) and (y.typ^.form <> fReal)) then MarkAt(y.pos, 'integer or pointer expected'); if y.typ^.form = fConst then Coerce(y, tI64); slots[n] := ToSlot(y); inc(n); @@ -581,7 +585,7 @@ bInc, bDec: begin Expression(x, nil); if (x.mode <> mVar) or not x.isVar or (x.typ^.form <> fInt) then - Mark('INC and DEC need an integer variable'); + MarkAt(x.pos, 'INC and DEC need an integer variable'); Save(x); if tok = sComma then begin Next; @@ -596,7 +600,7 @@ Expect(sRparen, ')'); end; -procedure ConstructCase(var x: TItem; c: PObj); +procedure ConstructCase(var x: TItem; c: PObj; const at: TPos); var f: PObj; a: TItem; begin Construct(x, c); @@ -610,30 +614,32 @@ if f <> nil then Expect(sComma, ','); end; Expect(sRparen, ')'); - end else if f <> nil then Mark(NameOf(c^.name) + ' needs its fields'); + end else if f <> nil then MarkAt(at, NameOf(c^.name) + ' needs its fields'); 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); -var o, f: PObj; y, z: TItem; t: PType; +var o, f: PObj; y, z: TItem; t: PType; start: TPos; begin + start := TokPos; o := QualIdent; called := false; - if o^.cls = oModule then Mark('a module is not a value'); + if o^.cls = oModule then MarkAt(SpanFrom(start), 'a module is not a value'); MakeItem(x, o); if x.mode = mBuiltin then begin Builtin(x); called := true; end else if x.mode = mCase then begin - ConstructCase(x, o); + ConstructCase(x, o, SpanFrom(start)); end; repeat + x.pos := SpanFrom(start); case tok of sPeriod: begin Next; - if (x.mode <> mVar) or (x.typ^.form <> fRecord) then Mark('not a record'); - if tok <> sIdent then Mark('field expected'); + if (x.mode <> mVar) or (x.typ^.form <> fRecord) then MarkAt(x.pos, 'not a record'); + if tok <> sIdent then MarkAt(MissingPos, 'field expected'); f := Find(x.typ^.scope, id); if f = nil then Mark('no field ' + NameOf(id)); if not f^.exported and (x.typ^.module <> curModule) then @@ -671,13 +677,15 @@ else break; end; until false; + x.pos := SpanFrom(start); end; procedure ArrayLiteral(var x: TItem; want: PType); var et, at: PType; e: TItem; slots: array[0..1023] of int64; n, i: longint; - off, es: int64; + off, es: int64; start: TPos; begin + start := TokPos; if (want = nil) or not (want^.form in [fArray, fSlice]) then Mark('an array literal needs a known array or slice type'); et := want^.base; @@ -699,7 +707,7 @@ Next; until false; Expect(sRbrak, ']'); - if (want^.form = fArray) and (n <> want^.len) then Mark('wrong number of elements'); + if (want^.form = fArray) and (n <> want^.len) then MarkAt(SpanFrom(start), 'wrong number of elements'); if n = 0 then begin MovRI(RAX, 0); SliceOf(x, want, 0); @@ -737,7 +745,7 @@ n := 0; if tok <> sRbrace then repeat - if tok <> sIdent then Mark('field expected'); + if tok <> sIdent then MarkAt(MissingPos, 'field expected'); f := Find(t^.scope, id); if f = nil then Mark('no field ' + NameOf(id)); if not f^.exported and (t^.module <> curModule) then Mark('field ' + NameOf(id) + ' isn''t exported'); @@ -756,20 +764,21 @@ { A set literal: the bits of the constant names, or'd at run time with those of the others. } procedure SetLiteral(var x: TItem; t: PType); -var e: TItem; bits, slot: int64; +var e: TItem; bits, slot: int64; start: TPos; begin + start := TokPos; Next; - if (t <> nil) and (t^.form <> fSet) then Mark('a set literal needs a set type'); + if (t <> nil) and (t^.form <> fSet) then MarkAt(SpanFrom(start), 'a set literal needs a set type'); bits := 0; slot := 0; if tok <> sRbrace then repeat if t = nil then Expression(e, nil) else Expression(e, t^.base); if t = nil then begin - if e.typ^.form <> fEnum then Mark('a set holds names of an enumeration'); - t := SetOf(e.typ); + if e.typ^.form <> fEnum then MarkAt(e.pos, 'a set holds names of an enumeration'); + t := SetOf(e.typ, e.pos); end; - if not Same(e.typ, t^.base) then Mark('not a name of ' + TypeName(t^.base)); + if not Same(e.typ, t^.base) then MarkAt(e.pos, 'not a name of ' + TypeName(t^.base)); if e.mode = mConst then bits := bits or (int64(1) shl e.val) else begin if slot = 0 then begin @@ -788,7 +797,7 @@ Next; until false; Expect(sRbrace, '}'); - if t = nil then Mark('{} needs a known set type'); + if t = nil then MarkAt(SpanFrom(start), '{} needs a known set type'); MakeConst(x, t, bits); if slot <> 0 then begin Load(RAX, Mem(RBP, slot), 8, false); @@ -799,8 +808,9 @@ end; procedure Factor(var x: TItem; want: PType); -var called, vol: boolean; t: PType; +var called, vol: boolean; t: PType; start: TPos; begin + start := TokPos; case tok of sInt, sChar: begin { only a hex number can be above high(I64), and it is a U64 } @@ -811,8 +821,8 @@ sString: begin MakeStr(x); Next end; sIdent: begin Designator(x, called); - if x.mode = mNone then Mark('this procedure returns nothing'); - if x.typ^.tuple then Mark('several results go only to a, b := ...'); + if x.mode = mNone then MarkAt(x.pos, 'this procedure returns nothing'); + if x.typ^.tuple then MarkAt(x.pos, 'several results go only to a, b := ...'); end; sLparen: begin Next; Expression(x, want); Expect(sRparen, ')') end; sNot: begin Next; Factor(x, nil); NotOp(x) end; @@ -829,13 +839,15 @@ Expect(sRparen, ')'); Convert(x, t); end; - else Mark('expression expected'); + else MarkAt(MissingPos, 'expression expected'); end; + x.pos := SpanFrom(start); end; procedure Term(var x: TItem; want: PType); -var op: TSym; y: TItem; L: longint; +var op: TSym; y: TItem; L: longint; start: TPos; begin + start := TokPos; Factor(x, want); while tok in [sTimes, sSlash, sDiv, sMod, sAnd, sShl, sShr] do begin op := tok; @@ -843,15 +855,18 @@ Op1(op, x, L); Factor(y, nil); Op2(op, x, y, L); + x.pos := SpanFrom(start); end; end; procedure SimpleExpr(var x: TItem; want: PType); -var op: TSym; y: TItem; L: longint; +var op: TSym; y: TItem; L: longint; start: TPos; begin + start := TokPos; if tok = sMinus then begin Next; Term(x, nil); + x.pos := SpanFrom(start); Neg(x); end else Term(x, want); while tok in [sPlus, sMinus, sOr, sXor] do begin @@ -860,6 +875,7 @@ Op1(op, x, L); Term(y, nil); Op2(op, x, y, L); + x.pos := SpanFrom(start); end; end; @@ -873,6 +889,7 @@ Op1(op, x, L); if op = sIn then SimpleExpr(y, nil) else SimpleExpr(y, x.typ); Op2(op, x, y, L); + x.pos := Join(x.pos, y.pos); end; end; @@ -963,7 +980,7 @@ lp: TLoop; old: PLoop; begin Next; - if tok <> sIdent then Mark('name expected'); + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); o := Lookup(id); if (o = nil) or (o^.cls <> oVar) or not (o^.typ^.form in [fInt, fEnum]) then Mark('a for loop needs an integer or enumeration variable'); @@ -982,7 +999,7 @@ Next; Expression(s, nil); step := ConstValue(s); - if step = 0 then Mark('the step can''t be zero'); + if step = 0 then MarkAt(s.pos, 'the step can''t be zero'); end; Expect(sDo, 'do'); exitL := NoLabel; @@ -1008,7 +1025,7 @@ procedure MatchStatement; var x: TItem; t: PType; c, f, o: PObj; p: int64; L, endL, n: longint; - seen: array[0..255] of boolean; hasElse: boolean; + seen: array[0..255] of boolean; hasElse: boolean; endAt: TPos; begin Next; Expression(x, nil); @@ -1027,7 +1044,7 @@ Statements; hasElse := true; end else begin - if tok <> sIdent then Mark('case expected'); + if tok <> sIdent then MarkAt(MissingPos, 'case expected'); c := t^.fields; while (c <> nil) and (c^.name <> id) do c := c^.next; if c = nil then Mark(NameOf(id) + ' isn''t a case of ' + TypeName(t)); @@ -1042,7 +1059,7 @@ f := c^.fields; n := 0; repeat - if tok <> sIdent then Mark('name expected'); + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); if f = nil then Mark('too many fields'); o := NewObj(oVar, id, f^.typ); o^.lev := 1; o^.ind := true; o^.isVar := true; @@ -1064,11 +1081,12 @@ FixLink(L); end; end; + endAt := TokPos; Expect(sEnd, 'end'); if not hasElse then begin c := t^.fields; while c <> nil do begin - if (c^.val > High(seen)) or not seen[c^.val] then Mark('no arm for ' + NameOf(c^.name)); + if (c^.val > High(seen)) or not seen[c^.val] then MarkAt(endAt, 'no arm for ' + NameOf(c^.name)); c := c^.next; end; end; @@ -1083,7 +1101,7 @@ n := 0; d[0] := x; repeat - if (d[n].mode <> mVar) or not d[n].isVar then Mark('can''t assign to this'); + if (d[n].mode <> mVar) or not d[n].isVar then MarkAt(d[n].pos, 'can''t assign to this'); Pin(d[n]); inc(n); if tok <> sComma then break; @@ -1094,7 +1112,7 @@ Expect(sBecomes, ':='); Designator(y, called); if not called or not y.typ^.tuple or (y.typ^.len <> n) then - Mark('needs a call with as many results as variables'); + MarkAt(y.pos, 'needs a call with as many results as variables'); f := y.typ^.fields; for i := 0 to n - 1 do begin z := y; @@ -1119,11 +1137,12 @@ { defer s: s is compiled where it stands, as a little subroutine of the procedure, jumped over; each way out of the statement list calls it. } procedure Defer; -var L, pos, oldDepth: longint; oldLoop: PLoop; oldDeferring: boolean; +var L, pos, oldDepth: longint; oldLoop: PLoop; oldDeferring: boolean; start: TPos; begin + start := TokPos; Next; - if directDefer then Mark('defer can''t be deferred'); - if numDefers > High(defers) then Mark('too many deferred statements'); + if directDefer then MarkAt(SpanFrom(start), 'defer can''t be deferred'); + if numDefers > High(defers) then MarkAt(SpanFrom(start), 'too many deferred statements'); L := NoLabel; Jmp(L); pos := pc; @@ -1143,15 +1162,16 @@ end; procedure Statement; -var x, y: TItem; called: boolean; m: int64; c: TCall; +var x, y: TItem; called: boolean; m: int64; c: TCall; start: TPos; begin + start := TokPos; NoteLine(CurLine); m := TempMark; case tok of sIdent: begin Designator(x, called); if tok = sBecomes then begin - if (x.mode <> mVar) or not x.isVar then Mark('can''t assign to this'); + if (x.mode <> mVar) or not x.isVar then MarkAt(x.pos, 'can''t assign to this'); Save(x); Next; Expression(y, x.typ); @@ -1162,7 +1182,7 @@ if (x.mode = mProc) or ((x.mode in [mVar, mReg]) and (x.typ^.form = fProc)) then begin BeginCall(c, x); EndCall(c, x); - end else Mark('not a statement'); + end else MarkAt(x.pos, 'not a statement'); end; end; sIf: IfStatement; @@ -1172,7 +1192,7 @@ sMatch: MatchStatement; sReturn: begin Next; - if deferring then Mark('return can''t leave a deferred statement'); + if deferring then MarkAt(SpanFrom(start), 'return can''t leave a deferred statement'); if tok = sSemicolon then begin RunDefers(0); ReturnNone; @@ -1193,12 +1213,12 @@ end; sBreak: begin Next; - if curLoop = nil then Mark('break outside a loop'); + if curLoop = nil then MarkAt(SpanFrom(start), 'break outside a loop'); RunDefers(curLoop^.base); Jmp(curLoop^.brk); end; sDefer: Defer; - else Mark('statement expected'); + else MarkAt(MissingPos, 'statement expected'); end; ReleaseTemps(m); end; @@ -1278,30 +1298,31 @@ CloseScope; end; -procedure CodeBody(p: PObj; sig: PType); -var q: PObj; ni, nf: longint; v: int64; +procedure CodeBody(p: PObj; sig: PType; const at: TPos); +var q: PObj; ni, nf: longint; v: int64; start: TPos; begin ni := 0; nf := 0; q := sig^.fields; while q <> nil do begin if not q^.isVar and not IsScalar(q^.typ) then - Mark('a code procedure takes integers, BOOL, reals, pointers and procedures'); + MarkAt(at, 'a code procedure takes integers, BOOL, reals, pointers and procedures'); if (q^.typ^.form = fReal) and not q^.isVar then inc(nf) else inc(ni); q := q^.next; end; - if (ni > 6) or (nf > 8) or sig^.variadic then Mark('too many parameters for a code procedure'); + if (ni > 6) or (nf > 8) or sig^.variadic then MarkAt(at, 'too many parameters for a code procedure'); if sig^.base <> nil then if sig^.base^.tuple then begin q := sig^.base^.fields; if (sig^.base^.len <> 2) or (q^.typ^.size <> 8) or (q^.next^.typ^.size <> 8) or not IsScalar(q^.typ) or not IsScalar(q^.next^.typ) or (q^.typ^.form = fReal) or (q^.next^.typ^.form = fReal) then - Mark('a code procedure returns two results only in rax and rdx'); - end else if not IsScalar(sig^.base) then Mark('a code procedure returns a single value'); + MarkAt(at, 'a code procedure returns two results only in rax and rdx'); + end else if not IsScalar(sig^.base) then MarkAt(at, 'a code procedure returns a single value'); BeginChunk(p^.chunk); repeat + start := TokPos; v := ConstExpr; - if (v < 0) or (v > 255) then Mark('a byte expected'); + if (v < 0) or (v > 255) then MarkAt(SpanFrom(start), 'a byte expected'); Put1(v); if tok <> sComma then break; Next; @@ -1310,16 +1331,18 @@ end; procedure ProcDecl; -var n, line: longint; exp: boolean; sig: PType; p: PObj; +var n, line: longint; exp: boolean; sig: PType; p: PObj; at: TPos; begin line := CurLine; Next; + at := TokPos; IdentDef(n, exp); + at := SpanFrom(at); sig := Signature; Expect(sSemicolon, ';'); p := Find(TopScope, n); if (p <> nil) and (p^.cls = oProc) and p^.fwd then begin - if not Same(p^.typ, sig) then Mark('not the signature it was declared with'); + if not Same(p^.typ, sig) then MarkAt(at, 'not the signature it was declared with'); if tok = sForward then Mark('declared forward twice'); p^.exported := p^.exported or exp; end else begin @@ -1339,7 +1362,7 @@ if tok = sCode then begin Next; p^.isCode := true; - CodeBody(p, sig); + CodeBody(p, sig, at); exit; end; if checkMode then SkipBody else Body(p, sig, line); @@ -1352,26 +1375,28 @@ { An extern procedure or variable: C's, reached through the quadword that holds its address. } procedure ExternDecl; -var n: longint; exp: boolean; o, q: PObj; t: PType; +var n: longint; exp: boolean; o, q: PObj; t: PType; at: TPos; begin Next; curModule^.usesC := true; if tok = sProc then begin Next; + at := TokPos; IdentDef(n, exp); + at := SpanFrom(at); inExtern := true; t := Signature; inExtern := false; q := t^.fields; while q <> nil do begin if q^.isVar or not IsScalar(q^.typ) then - Mark('C takes integers, BOOL, reals, pointers and procedures'); + MarkAt(at, 'C takes integers, BOOL, reals, pointers and procedures'); q := q^.next; end; - if (t^.base <> nil) and not IsScalar(t^.base) then Mark('C returns a single value'); + if (t^.base <> nil) and not IsScalar(t^.base) then MarkAt(at, 'C returns a single value'); o := NewObj(oProc, n, t); end else begin - if tok <> sVar then Mark('proc or var expected'); + if tok <> sVar then MarkAt(MissingPos, 'proc or var expected'); Next; IdentDef(n, exp); Expect(sColon, ':'); @@ -1389,7 +1414,7 @@ procedure Declarations(top: boolean); var n, i, k: longint; exp: boolean; x: TItem; o: PObj; t: PType; - names: array[0..63] of longint; exps: array[0..63] of boolean; + names: array[0..63] of longint; exps: array[0..63] of boolean; start: TPos; begin repeat case tok of @@ -1400,8 +1425,9 @@ t := nil; if tok = sColon then begin Next; + start := TokPos; t := ParseType; - if t <> tError then Mark('only an ERROR constant has a type'); + if t <> tError then MarkAt(SpanFrom(start), 'only an ERROR constant has a type'); end; Expect(sEql, '='); Expression(x, nil); @@ -1510,18 +1536,20 @@ { The arguments of an instance: types, or procedures named. } procedure ParseArgs(var args: TArgs); -var o: PObj; +var o: PObj; start: TPos; begin Next; repeat if args.n > High(args.t) then Mark('too many arguments'); args.o[args.n] := nil; + start := TokPos; if tok = sIdent then begin o := QualIdent; if o^.cls = oProc then args.o[args.n] := o - else if o^.cls <> oType then Mark('a type or a procedure expected'); + else if o^.cls <> oType then MarkAt(SpanFrom(start), 'a type or a procedure expected'); args.t[args.n] := o^.typ; end else args.t[args.n] := ParseType; + args.pos[args.n] := SpanFrom(start); inc(args.n); if tok <> sComma then break; Next; @@ -1532,14 +1560,14 @@ { A generic module's parameters, bound to the instance's arguments: a type parameter names its type, a procedure parameter its procedure. } procedure Params(m: PModule); -var i: longint; o, a: PObj; sig: PType; s: shortstring; +var i: longint; o, a: PObj; sig: PType; s: shortstring; at: TPos; begin i := 0; s := NameOf(m^.name) + '('; Next; repeat - if (tok <> sIdent) or (i >= m^.args.n) or (m^.args.o[i] <> nil) then - Mark('needs a type for each type parameter'); + if (tok <> sIdent) or (i >= m^.args.n) then MarkAt(m^.args.at, 'needs a type for each type parameter'); + if m^.args.o[i] <> nil then MarkAt(m^.args.pos[i], 'needs a type for each type parameter'); Declare(NewObj(oType, id, m^.args.t[i])); s := s + TypeName(m^.args.t[i]) + ','; inc(i); @@ -1549,23 +1577,27 @@ until false; while tok = sSemicolon do begin Next; - if tok <> sIdent then Mark('name expected'); + if tok <> sIdent then MarkAt(MissingPos, 'name expected'); + at := TokPos; o := NewObj(oProc, id, nil); Next; Expect(sColon, ':'); Expect(sProc, 'proc'); sig := Signature; - if i >= m^.args.n then Mark('needs a procedure for ' + NameOf(o^.name)); + if i >= m^.args.n then MarkAt(m^.args.at, 'needs a procedure for ' + NameOf(o^.name)); a := m^.args.o[i]; - if (a = nil) or not Same(a^.typ, sig) then - Mark('needs a procedure with the signature of ' + NameOf(o^.name)); + if (a = nil) or not Same(a^.typ, sig) then begin + Error(m^.args.pos[i], 'needs a procedure with the signature of ' + NameOf(o^.name)); + Note(at, NameOf(o^.name) + ' is declared here'); + Finish; + end; o^.typ := a^.typ; o^.chunk := a^.chunk; o^.isCode := a^.isCode; o^.ext := a^.ext; Declare(o); s := s + NameOf(a^.module^.name) + '.' + NameOf(a^.name) + ','; inc(i); end; Expect(sRparen, ')'); - if i <> m^.args.n then Mark('too many arguments'); + if i <> m^.args.n then MarkAt(m^.args.at, 'too many arguments'); s[length(s)] := ')'; m^.sname := Name(s); end; @@ -1586,7 +1618,7 @@ var st: TScanState; saved: array[0..MaxDepth - 1] of longint; d: longint; oldMod: PModule; oldFile: longint; oldCheck: boolean; m, im: PModule; - imp: PImport; lib: PLib; alias, mname, line, oldPath: longint; o: PObj; body: longint; iargs: TArgs; + imp: PImport; lib: PLib; start: TPos; alias, mname, line, oldPath: longint; o: PObj; body: longint; iargs: TArgs; begin SaveScan(st); SaveScopes(d, saved); @@ -1616,23 +1648,25 @@ if (tok <> sIdent) or (id <> n) then Mark('this file must hold module ' + NameOf(n)); Next; if tok = sLparen then Params(m) - else if args.n > 0 then Mark(NameOf(n) + ' isn''t generic'); + else if args.n > 0 then MarkAt(args.at, NameOf(n) + ' isn''t generic'); Expect(sSemicolon, ';'); while tok = sImport do begin Next; repeat - if tok <> sIdent then Mark('module name expected'); + if tok <> sIdent then MarkAt(MissingPos, 'module name expected'); + start := TokPos; alias := id; mname := id; iargs.n := 0; Next; if tok = sBecomes then begin Next; - if tok <> sIdent then Mark('module name expected'); + if tok <> sIdent then MarkAt(MissingPos, 'module name expected'); mname := id; Next; if tok = sLparen then ParseArgs(iargs); end; + iargs.at := SpanFrom(start); im := ImportModule(mname, iargs); o := NewObj(oModule, alias, nil); o^.module := im; @@ -1679,7 +1713,7 @@ end else Expect(sEnd, 'end'); if (tok <> sIdent) or (id <> n) then Mark('end ' + NameOf(n) + ' expected'); Next; - if tok <> sPeriod then Mark('. expected'); + if tok <> sPeriod then MarkAt(MissingPos, '. expected'); o := m^.first; while o <> nil do begin if (o^.cls = oProc) and o^.fwd then Mark(NameOf(o^.name) + ' is declared forward but never defined'); @@ -1759,7 +1793,7 @@ m := FindModule(name, args); if m <> nil then exit(m); for i := 0 to numPending - 1 do - if IsModule(pending[i], name, args) then Mark(NameOf(name) + ' imports itself'); + if IsModule(pending[i], name, args) then MarkAt(args.at, NameOf(name) + ' imports itself'); for i := -1 to numInc do begin if i = -1 then dir := mainDir else if i = numInc then dir := libDir @@ -1773,7 +1807,7 @@ end; end; end; - Mark('can''t find module ' + NameOf(name)); + MarkAt(args.at, 'can''t find module ' + NameOf(name)); ImportModule := nil; end; @@ -1789,6 +1823,7 @@ if i > 0 then base := copy(base, 1, i - 1); if base = '' then Fatal('no module in ' + path); n := Name(base); + none.at := TokPos; if n <> nameRt then ImportModule(nameRt, none); if FindModule(n, none) <> nil then CompileMain := FindModule(n, none) else CompileMain := CompileFile(path, n, none, false); diff --git a/src/scan.pas b/src/scan.pas index dac167c..96463b8 100644 --- a/src/scan.pas +++ b/src/scan.pas @@ -41,6 +41,7 @@ buf: PChar; len, pos, line, lineStart: longint; tokPos, tokLine, tokLineStart: longint; + prevEnd: longint; { where the symbol before this one ends } tok: TSym; ival: int64; rval: double; @@ -66,9 +67,13 @@ function Open(const path: shortstring): boolean; procedure Next; procedure Mark(const msg: shortstring); +procedure MarkAt(const p: TPos; const msg: shortstring); procedure SaveScan(var st: TScanState); procedure RestoreScan(const st: TScanState); function TokPos: TPos; +function AfterPrev: TPos; +function MissingPos: TPos; +function SpanFrom(const p: TPos): TPos; function CurPath: shortstring; function CurLine: longint; @@ -171,6 +176,34 @@ TokPos.b := cur.pos; end; +{ The place just after the symbol before the current one, where a + missing symbol belongs } +function AfterPrev: TPos; +begin + AfterPrev.f := cur.f; + AfterPrev.a := cur.prevEnd; + AfterPrev.b := cur.prevEnd; +end; + +{ Where to say a symbol is missing: at the current symbol, unless it + starts a later line than the symbol before it, which is more likely + where the missing one belongs } +function MissingPos: TPos; +var i: longint; +begin + MissingPos := TokPos; + for i := cur.prevEnd to cur.tokPos - 1 do + if cur.buf[i] = #10 then MissingPos := AfterPrev; +end; + +{ From the start of p to the end of the symbol before the current one: + the whole of a construct that has just been read } +function SpanFrom(const p: TPos): TPos; +begin + SpanFrom := p; + SpanFrom.b := cur.prevEnd; +end; + function CurPath: shortstring; begin CurPath := cur.path; @@ -183,7 +216,20 @@ procedure Mark(const msg: shortstring); begin - Error(TokPos, msg); + MarkAt(TokPos, msg); +end; + +{ Report at the bytes a to b of the file being read } +procedure MarkBytes(a, b: longint; const msg: shortstring); +var p: TPos; +begin + p.f := cur.f; p.a := a; p.b := b; + MarkAt(p, msg); +end; + +procedure MarkAt(const p: TPos; const msg: shortstring); +begin + Error(p, msg); Finish; end; @@ -298,9 +344,10 @@ { One character of a character or string literal, at buf[pos]: its code point, or for \xHH, minus one minus the byte. } function LitChar(inString: boolean): longint; -var c: char; v, d, n: longint; +var c: char; v, d, n, esc: longint; begin c := cur.buf[cur.pos]; + esc := cur.pos; if c = '\' then begin inc(cur.pos); c := cur.buf[cur.pos]; @@ -312,28 +359,28 @@ '0': v := 0; '\', '''', '"': v := ord(c); 'x': begin - if not inString then Mark('\x only in strings'); + if not inString then MarkBytes(esc, cur.pos, '\x only in strings'); d := HexVal(cur.buf[cur.pos]); n := HexVal(cur.buf[cur.pos + 1]); - if (d < 0) or (n < 0) then Mark('\x needs two hex digits'); + if (d < 0) or (n < 0) then MarkBytes(esc, cur.pos + 2, '\x needs two hex digits'); inc(cur.pos, 2); v := -1 - (d * 16 + n); end; 'u': begin - if cur.buf[cur.pos] <> '{' then Mark('\u needs {'); + if cur.buf[cur.pos] <> '{' then MarkBytes(esc, cur.pos, '\u needs {'); inc(cur.pos); v := 0; n := 0; while HexVal(cur.buf[cur.pos]) >= 0 do begin v := v * 16 + HexVal(cur.buf[cur.pos]); inc(n); inc(cur.pos); - if n > 6 then Mark('code point too big'); + if n > 6 then MarkBytes(esc, cur.pos, 'code point too big'); end; - if (n = 0) or (cur.buf[cur.pos] <> '}') then Mark('bad \u{...}'); + if (n = 0) or (cur.buf[cur.pos] <> '}') then MarkBytes(esc, cur.pos, 'bad \u{...}'); inc(cur.pos); if (v > $10FFFF) or ((v >= $D800) and (v <= $DFFF)) then - Mark('not a code point'); + MarkBytes(esc, cur.pos, 'not a code point'); end; - else Mark('unknown escape'); + else MarkBytes(esc, cur.pos, 'unknown escape'); end; end else if byte(c) >= $80 then v := Utf8(cur.pos) @@ -349,14 +396,15 @@ { Symbols } procedure Comment; -var depth: longint; c: char; +var depth, open: longint; c: char; begin depth := 1; + open := cur.pos; inc(cur.pos, 2); repeat c := cur.buf[cur.pos]; if c = #0 then begin - if cur.pos >= cur.len then Mark('comment not closed'); + if cur.pos >= cur.len then MarkBytes(open, open + 2, 'comment not closed'); inc(cur.pos); end else if (c = '(') and (cur.buf[cur.pos + 1] = '*') then begin inc(depth); inc(cur.pos, 2) @@ -422,6 +470,7 @@ procedure Next; var c: char; start, h, v: longint; begin + cur.prevEnd := cur.pos; repeat c := cur.buf[cur.pos]; while c in [' ', #9, #13, #10] do begin @@ -509,13 +558,13 @@ '^': begin inc(cur.pos); tok := sArrow end; '|': begin inc(cur.pos); tok := sBar end; #0: begin - if cur.pos < cur.len then Mark('NUL character'); + if cur.pos < cur.len then MarkBytes(cur.pos, cur.pos + 1, 'NUL character'); tok := sEof; end; else if byte(c) >= $80 then Mark('text outside strings, characters and comments must be ASCII'); - Mark('unexpected character'); + MarkBytes(cur.pos, cur.pos + 1, 'unexpected character'); end; end; diff --git a/src/sym.pas b/src/sym.pas index 21636cc..6c26e0a 100644 --- a/src/sym.pas +++ b/src/sym.pas @@ -17,7 +17,7 @@ interface -uses scan; +uses scan, diag; type TForm = (fNone, fBool, fInt, fReal, fConst, fNil, fStr, fPtr, fArray, @@ -80,6 +80,8 @@ n: longint; t: array[0..7] of PType; o: array[0..7] of PObj; + pos: array[0..7] of TPos; { where each argument is, for messages } + at: TPos; { where the import is } end; TImport = record diff --git a/test/err/Assign.err b/test/err/Assign.err index 45cb220..52fa89c 100644 --- a/test/err/Assign.err +++ b/test/err/Assign.err @@ -1,4 +1,4 @@ -test/err/Assign.raz:5:11: error: can't use I32 as I64 +test/err/Assign.raz:5:10: error: can't use I32 as I64 5 | a := b; - | ^ + | ^ raz: 1 error diff --git a/test/err/AtAnd.err b/test/err/AtAnd.err new file mode 100644 index 0000000..39e1f14 --- /dev/null +++ b/test/err/AtAnd.err @@ -0,0 +1,4 @@ +test/err/AtAnd.raz:5:16: error: and, or need two BOOLs + 5 | b := b and (x + 1); + | ^^^^^^^ +raz: 1 error diff --git a/test/err/AtAnd.raz b/test/err/AtAnd.raz new file mode 100644 index 0000000..e0102b3 --- /dev/null +++ b/test/err/AtAnd.raz @@ -0,0 +1,7 @@ +module AtAnd; +proc main*; +var b: BOOL; x: I64; +begin + b := b and (x + 1); +end; +end AtAnd. diff --git a/test/err/AtArgType.err b/test/err/AtArgType.err new file mode 100644 index 0000000..a29e882 --- /dev/null +++ b/test/err/AtArgType.err @@ -0,0 +1,4 @@ +test/err/AtArgType.raz:7:8: error: can't use BOOL as I64 + 7 | Id(b); + | ^ +raz: 1 error diff --git a/test/err/AtArgType.raz b/test/err/AtArgType.raz new file mode 100644 index 0000000..18f30e3 --- /dev/null +++ b/test/err/AtArgType.raz @@ -0,0 +1,9 @@ +module AtArgType; +proc Id(a: I64): I64; +begin return a; end; +proc main*; +var b: BOOL; +begin + Id(b); +end; +end AtArgType. diff --git a/test/err/AtBinary.err b/test/err/AtBinary.err new file mode 100644 index 0000000..5f1e4ce --- /dev/null +++ b/test/err/AtBinary.err @@ -0,0 +1,4 @@ +test/err/AtBinary.raz:5:10: error: can't combine I64 and BOOL + 5 | x := (x + 2) * b; + | ^^^^^^^^^^^ +raz: 1 error diff --git a/test/err/AtBinary.raz b/test/err/AtBinary.raz new file mode 100644 index 0000000..92f2d8d --- /dev/null +++ b/test/err/AtBinary.raz @@ -0,0 +1,7 @@ +module AtBinary; +proc main*; +var x: I64; b: BOOL; +begin + x := (x + 2) * b; +end; +end AtBinary. diff --git a/test/err/AtCall.err b/test/err/AtCall.err new file mode 100644 index 0000000..48f6069 --- /dev/null +++ b/test/err/AtCall.err @@ -0,0 +1,4 @@ +test/err/AtCall.raz:5:10: error: not a procedure + 5 | x := x(1); + | ^ +raz: 1 error diff --git a/test/err/AtCall.raz b/test/err/AtCall.raz new file mode 100644 index 0000000..76966e6 --- /dev/null +++ b/test/err/AtCall.raz @@ -0,0 +1,7 @@ +module AtCall; +proc main*; +var x: I64; +begin + x := x(1); +end; +end AtCall. diff --git a/test/err/AtCondition.err b/test/err/AtCondition.err new file mode 100644 index 0000000..046c122 --- /dev/null +++ b/test/err/AtCondition.err @@ -0,0 +1,4 @@ +test/err/AtCondition.raz:5:8: error: a condition is a BOOL + 5 | if x + 1 then end; + | ^^^^^ +raz: 1 error diff --git a/test/err/AtCondition.raz b/test/err/AtCondition.raz new file mode 100644 index 0000000..32f8f9f --- /dev/null +++ b/test/err/AtCondition.raz @@ -0,0 +1,7 @@ +module AtCondition; +proc main*; +var x: I64; +begin + if x + 1 then end; +end; +end AtCondition. diff --git a/test/err/AtConstFit.err b/test/err/AtConstFit.err new file mode 100644 index 0000000..ed4e72c --- /dev/null +++ b/test/err/AtConstFit.err @@ -0,0 +1,4 @@ +test/err/AtConstFit.raz:5:10: error: constant doesn't fit I32 + 5 | x := 5 + 3000000000; + | ^^^^^^^^^^^^^^ +raz: 1 error diff --git a/test/err/AtConstFit.raz b/test/err/AtConstFit.raz new file mode 100644 index 0000000..c5c02f7 --- /dev/null +++ b/test/err/AtConstFit.raz @@ -0,0 +1,7 @@ +module AtConstFit; +proc main*; +var x: I32; +begin + x := 5 + 3000000000; +end; +end AtConstFit. diff --git a/test/err/AtConvert.err b/test/err/AtConvert.err new file mode 100644 index 0000000..8c40700 --- /dev/null +++ b/test/err/AtConvert.err @@ -0,0 +1,4 @@ +test/err/AtConvert.raz:5:14: error: can't convert BOOL to I64 + 5 | x := I64(b); + | ^ +raz: 1 error diff --git a/test/err/AtConvert.raz b/test/err/AtConvert.raz new file mode 100644 index 0000000..7f9d912 --- /dev/null +++ b/test/err/AtConvert.raz @@ -0,0 +1,7 @@ +module AtConvert; +proc main*; +var b: BOOL; x: I64; +begin + x := I64(b); +end; +end AtConvert. diff --git a/test/err/AtDeref.err b/test/err/AtDeref.err new file mode 100644 index 0000000..3817192 --- /dev/null +++ b/test/err/AtDeref.err @@ -0,0 +1,4 @@ +test/err/AtDeref.raz:5:10: error: not a pointer + 5 | y := x^; + | ^ +raz: 1 error diff --git a/test/err/AtDeref.raz b/test/err/AtDeref.raz new file mode 100644 index 0000000..49395a9 --- /dev/null +++ b/test/err/AtDeref.raz @@ -0,0 +1,7 @@ +module AtDeref; +proc main*; +var x, y: I64; +begin + y := x^; +end; +end AtDeref. diff --git a/test/err/AtDivZero.err b/test/err/AtDivZero.err new file mode 100644 index 0000000..317318b --- /dev/null +++ b/test/err/AtDivZero.err @@ -0,0 +1,4 @@ +test/err/AtDivZero.raz:5:10: error: division by zero + 5 | x := 7 div (3 - 3); + | ^^^^^^^^^^^^^ +raz: 1 error diff --git a/test/err/AtDivZero.raz b/test/err/AtDivZero.raz new file mode 100644 index 0000000..37ce36d --- /dev/null +++ b/test/err/AtDivZero.raz @@ -0,0 +1,7 @@ +module AtDivZero; +proc main*; +var x: I64; +begin + x := 7 div (3 - 3); +end; +end AtDivZero. diff --git a/test/err/AtIndex.err b/test/err/AtIndex.err new file mode 100644 index 0000000..5766d63 --- /dev/null +++ b/test/err/AtIndex.err @@ -0,0 +1,4 @@ +test/err/AtIndex.raz:5:12: error: an index is an integer + 5 | x := a[b]; + | ^ +raz: 1 error diff --git a/test/err/AtIndex.raz b/test/err/AtIndex.raz new file mode 100644 index 0000000..0effec5 --- /dev/null +++ b/test/err/AtIndex.raz @@ -0,0 +1,7 @@ +module AtIndex; +proc main*; +var a: [4]I64; b: BOOL; x: I64; +begin + x := a[b]; +end; +end AtIndex. diff --git a/test/err/AtIndexConst.err b/test/err/AtIndexConst.err new file mode 100644 index 0000000..64d66e0 --- /dev/null +++ b/test/err/AtIndexConst.err @@ -0,0 +1,4 @@ +test/err/AtIndexConst.raz:5:12: error: index out of range + 5 | x := a[2 + 3]; + | ^^^^^ +raz: 1 error diff --git a/test/err/AtIndexConst.raz b/test/err/AtIndexConst.raz new file mode 100644 index 0000000..4448aa1 --- /dev/null +++ b/test/err/AtIndexConst.raz @@ -0,0 +1,7 @@ +module AtIndexConst; +proc main*; +var a: [4]I64; x: I64; +begin + x := a[2 + 3]; +end; +end AtIndexConst. diff --git a/test/err/AtMany.err b/test/err/AtMany.err new file mode 100644 index 0000000..451bf9b --- /dev/null +++ b/test/err/AtMany.err @@ -0,0 +1,4 @@ +test/err/AtMany.raz:7:16: error: too many arguments + 7 | x := Id(1, 2 * 3); + | ^^^^^ +raz: 1 error diff --git a/test/err/AtMany.raz b/test/err/AtMany.raz new file mode 100644 index 0000000..ae23c75 --- /dev/null +++ b/test/err/AtMany.raz @@ -0,0 +1,9 @@ +module AtMany; +proc Id(a: I64): I64; +begin return a; end; +proc main*; +var x: I64; +begin + x := Id(1, 2 * 3); +end; +end AtMany. diff --git a/test/err/AtMatch.err b/test/err/AtMatch.err new file mode 100644 index 0000000..6495d02 --- /dev/null +++ b/test/err/AtMatch.err @@ -0,0 +1,4 @@ +test/err/AtMatch.raz:5:11: error: match needs a variant or an enumeration + 5 | match x + 1 do end; + | ^^^^^ +raz: 1 error diff --git a/test/err/AtMatch.raz b/test/err/AtMatch.raz new file mode 100644 index 0000000..43a165a --- /dev/null +++ b/test/err/AtMatch.raz @@ -0,0 +1,7 @@ +module AtMatch; +proc main*; +var x: I64; +begin + match x + 1 do end; +end; +end AtMatch. diff --git a/test/err/AtNegate.err b/test/err/AtNegate.err new file mode 100644 index 0000000..1380a8f --- /dev/null +++ b/test/err/AtNegate.err @@ -0,0 +1,4 @@ +test/err/AtNegate.raz:5:10: error: can't negate BOOL + 5 | x := -b; + | ^^ +raz: 1 error diff --git a/test/err/AtNegate.raz b/test/err/AtNegate.raz new file mode 100644 index 0000000..a98e098 --- /dev/null +++ b/test/err/AtNegate.raz @@ -0,0 +1,7 @@ +module AtNegate; +proc main*; +var b: BOOL; x: I64; +begin + x := -b; +end; +end AtNegate. diff --git a/test/err/AtNot.err b/test/err/AtNot.err new file mode 100644 index 0000000..ee2041e --- /dev/null +++ b/test/err/AtNot.err @@ -0,0 +1,4 @@ +test/err/AtNot.raz:5:14: error: not needs BOOL or an integer + 5 | b := not s; + | ^ +raz: 1 error diff --git a/test/err/AtNot.raz b/test/err/AtNot.raz new file mode 100644 index 0000000..745d2cd --- /dev/null +++ b/test/err/AtNot.raz @@ -0,0 +1,7 @@ +module AtNot; +proc main*; +var s: []U8; b: BOOL; +begin + b := not s; +end; +end AtNot. diff --git a/test/err/AtNotValue.err b/test/err/AtNotValue.err new file mode 100644 index 0000000..f4fd17c --- /dev/null +++ b/test/err/AtNotValue.err @@ -0,0 +1,4 @@ +test/err/AtNotValue.raz:5:10: error: not a value + 5 | x := I64 + 1; + | ^^^ +raz: 1 error diff --git a/test/err/AtNotValue.raz b/test/err/AtNotValue.raz new file mode 100644 index 0000000..b10f2fa --- /dev/null +++ b/test/err/AtNotValue.raz @@ -0,0 +1,7 @@ +module AtNotValue; +proc main*; +var x: I64; +begin + x := I64 + 1; +end; +end AtNotValue. diff --git a/test/err/AtPAdr.err b/test/err/AtPAdr.err new file mode 100644 index 0000000..616fd7b --- /dev/null +++ b/test/err/AtPAdr.err @@ -0,0 +1,4 @@ +test/err/AtPAdr.raz:5:14: error: ADR needs a variable + 5 | p := ADR(1); + | ^ +raz: 1 error diff --git a/test/err/AtPAdr.raz b/test/err/AtPAdr.raz new file mode 100644 index 0000000..1557a4e --- /dev/null +++ b/test/err/AtPAdr.raz @@ -0,0 +1,7 @@ +module AtPAdr; +proc main*; +var p: ^I64; +begin + p := ADR(1); +end; +end AtPAdr. diff --git a/test/err/AtPArrayLen.err b/test/err/AtPArrayLen.err new file mode 100644 index 0000000..4d40734 --- /dev/null +++ b/test/err/AtPArrayLen.err @@ -0,0 +1,4 @@ +test/err/AtPArrayLen.raz:2:9: error: bad array length + 2 | var a: [0]I64; + | ^ +raz: 1 error diff --git a/test/err/AtPArrayLen.raz b/test/err/AtPArrayLen.raz new file mode 100644 index 0000000..b113f1b --- /dev/null +++ b/test/err/AtPArrayLen.raz @@ -0,0 +1,6 @@ +module AtPArrayLen; +var a: [0]I64; +proc main*; +begin +end; +end AtPArrayLen. diff --git a/test/err/AtPByte.err b/test/err/AtPByte.err new file mode 100644 index 0000000..986cd91 --- /dev/null +++ b/test/err/AtPByte.err @@ -0,0 +1,4 @@ +test/err/AtPByte.raz:3:6: error: a byte expected + 3 | code 300; + | ^^^ +raz: 1 error diff --git a/test/err/AtPByte.raz b/test/err/AtPByte.raz new file mode 100644 index 0000000..936fdbc --- /dev/null +++ b/test/err/AtPByte.raz @@ -0,0 +1,4 @@ +module AtPByte; +proc f(a: I64); +code 300; +end AtPByte. diff --git a/test/err/AtPCantAssign.err b/test/err/AtPCantAssign.err new file mode 100644 index 0000000..9313873 --- /dev/null +++ b/test/err/AtPCantAssign.err @@ -0,0 +1,4 @@ +test/err/AtPCantAssign.raz:7:8: error: can't assign to this + 7 | a, k := two(); + | ^ +raz: 1 error diff --git a/test/err/AtPCantAssign.raz b/test/err/AtPCantAssign.raz new file mode 100644 index 0000000..2806e85 --- /dev/null +++ b/test/err/AtPCantAssign.raz @@ -0,0 +1,9 @@ +module AtPCantAssign; +const k = 1; +proc two: (I64, I64); begin return 1, 2; end; +proc main*; +var a: I64; +begin + a, k := two(); +end; +end AtPCantAssign. diff --git a/test/err/AtPChar.err b/test/err/AtPChar.err new file mode 100644 index 0000000..0c3c92e --- /dev/null +++ b/test/err/AtPChar.err @@ -0,0 +1,4 @@ +test/err/AtPChar.raz:5:12: error: unexpected character + 5 | a := 1 ? 2; + | ^ +raz: 1 error diff --git a/test/err/AtPChar.raz b/test/err/AtPChar.raz new file mode 100644 index 0000000..e71836a --- /dev/null +++ b/test/err/AtPChar.raz @@ -0,0 +1,7 @@ +module AtPChar; +proc main*; +var a: I64; +begin + a := 1 ? 2; +end; +end AtPChar. diff --git a/test/err/AtPComment.err b/test/err/AtPComment.err new file mode 100644 index 0000000..1d5d7c4 --- /dev/null +++ b/test/err/AtPComment.err @@ -0,0 +1,4 @@ +test/err/AtPComment.raz:5:1: error: comment not closed + 5 | (* never closed + | ^^ +raz: 1 error diff --git a/test/err/AtPComment.raz b/test/err/AtPComment.raz new file mode 100644 index 0000000..3728d16 --- /dev/null +++ b/test/err/AtPComment.raz @@ -0,0 +1,6 @@ +module AtPComment; +proc main*; +begin +end; +(* never closed +end AtPComment. diff --git a/test/err/AtPConstExpr.err b/test/err/AtPConstExpr.err new file mode 100644 index 0000000..01c774d --- /dev/null +++ b/test/err/AtPConstExpr.err @@ -0,0 +1,4 @@ +test/err/AtPConstExpr.raz:4:9: error: constant expected + 4 | var a: [n]I64; + | ^ +raz: 1 error diff --git a/test/err/AtPConstExpr.raz b/test/err/AtPConstExpr.raz new file mode 100644 index 0000000..ba36e1b --- /dev/null +++ b/test/err/AtPConstExpr.raz @@ -0,0 +1,7 @@ +module AtPConstExpr; +proc main*; +var n: I64; +var a: [n]I64; +begin +end; +end AtPConstExpr. diff --git a/test/err/AtPElems.err b/test/err/AtPElems.err new file mode 100644 index 0000000..3fd79b9 --- /dev/null +++ b/test/err/AtPElems.err @@ -0,0 +1,4 @@ +test/err/AtPElems.raz:5:10: error: wrong number of elements + 5 | a := [1, 2]; + | ^^^^^^ +raz: 1 error diff --git a/test/err/AtPElems.raz b/test/err/AtPElems.raz new file mode 100644 index 0000000..15e18ea --- /dev/null +++ b/test/err/AtPElems.raz @@ -0,0 +1,7 @@ +module AtPElems; +proc main*; +var a: [3]I64; +begin + a := [1, 2]; +end; +end AtPElems. diff --git a/test/err/AtPEscape.err b/test/err/AtPEscape.err new file mode 100644 index 0000000..476b4b0 --- /dev/null +++ b/test/err/AtPEscape.err @@ -0,0 +1,4 @@ +test/err/AtPEscape.raz:5:12: error: unknown escape + 5 | s := "a\q"; + | ^^ +raz: 1 error diff --git a/test/err/AtPEscape.raz b/test/err/AtPEscape.raz new file mode 100644 index 0000000..d7ce6e2 --- /dev/null +++ b/test/err/AtPEscape.raz @@ -0,0 +1,7 @@ +module AtPEscape; +proc main*; +var s: [8]U8; +begin + s := "a\q"; +end; +end AtPEscape. diff --git a/test/err/AtPInc.err b/test/err/AtPInc.err new file mode 100644 index 0000000..a335781 --- /dev/null +++ b/test/err/AtPInc.err @@ -0,0 +1,4 @@ +test/err/AtPInc.raz:5:9: error: INC and DEC need an integer variable + 5 | INC(a); + | ^ +raz: 1 error diff --git a/test/err/AtPInc.raz b/test/err/AtPInc.raz new file mode 100644 index 0000000..4bf1649 --- /dev/null +++ b/test/err/AtPInc.raz @@ -0,0 +1,7 @@ +module AtPInc; +proc main*; +var a: BOOL; +begin + INC(a); +end; +end AtPInc. diff --git a/test/err/AtPLen.err b/test/err/AtPLen.err new file mode 100644 index 0000000..87adb77 --- /dev/null +++ b/test/err/AtPLen.err @@ -0,0 +1,4 @@ +test/err/AtPLen.raz:5:14: error: LEN needs an array or slice + 5 | a := LEN(a); + | ^ +raz: 1 error diff --git a/test/err/AtPLen.raz b/test/err/AtPLen.raz new file mode 100644 index 0000000..6536bb3 --- /dev/null +++ b/test/err/AtPLen.raz @@ -0,0 +1,7 @@ +module AtPLen; +proc main*; +var a: I64; +begin + a := LEN(a); +end; +end AtPLen. diff --git a/test/err/AtPNewVar.err b/test/err/AtPNewVar.err new file mode 100644 index 0000000..b63f007 --- /dev/null +++ b/test/err/AtPNewVar.err @@ -0,0 +1,4 @@ +test/err/AtPNewVar.raz:5:9: error: NEW needs a pointer variable + 5 | NEW(a, a); + | ^ +raz: 1 error diff --git a/test/err/AtPNewVar.raz b/test/err/AtPNewVar.raz new file mode 100644 index 0000000..1f4bddb --- /dev/null +++ b/test/err/AtPNewVar.raz @@ -0,0 +1,7 @@ +module AtPNewVar; +proc main*; +var a: I64; +begin + NEW(a, a); +end; +end AtPNewVar. diff --git a/test/err/AtPNoResult.err b/test/err/AtPNoResult.err new file mode 100644 index 0000000..2e309e0 --- /dev/null +++ b/test/err/AtPNoResult.err @@ -0,0 +1,4 @@ +test/err/AtPNoResult.raz:8:10: error: this procedure returns nothing + 8 | a := p() + 1; + | ^^^ +raz: 1 error diff --git a/test/err/AtPNoResult.raz b/test/err/AtPNoResult.raz new file mode 100644 index 0000000..f72273c --- /dev/null +++ b/test/err/AtPNoResult.raz @@ -0,0 +1,10 @@ +module AtPNoResult; +proc p; +begin +end; +proc main*; +var a: I64; +begin + a := p() + 1; +end; +end AtPNoResult. diff --git a/test/err/AtPNotRecord.err b/test/err/AtPNotRecord.err new file mode 100644 index 0000000..4b068de --- /dev/null +++ b/test/err/AtPNotRecord.err @@ -0,0 +1,4 @@ +test/err/AtPNotRecord.raz:5:10: error: not a record + 5 | a := a.f; + | ^ +raz: 1 error diff --git a/test/err/AtPNotRecord.raz b/test/err/AtPNotRecord.raz new file mode 100644 index 0000000..331e902 --- /dev/null +++ b/test/err/AtPNotRecord.raz @@ -0,0 +1,7 @@ +module AtPNotRecord; +proc main*; +var a: I64; +begin + a := a.f; +end; +end AtPNotRecord. diff --git a/test/err/AtPNotStmt.err b/test/err/AtPNotStmt.err new file mode 100644 index 0000000..95511a7 --- /dev/null +++ b/test/err/AtPNotStmt.err @@ -0,0 +1,4 @@ +test/err/AtPNotStmt.raz:5:5: error: not a statement + 5 | a; + | ^ +raz: 1 error diff --git a/test/err/AtPNotStmt.raz b/test/err/AtPNotStmt.raz new file mode 100644 index 0000000..ed814f3 --- /dev/null +++ b/test/err/AtPNotStmt.raz @@ -0,0 +1,7 @@ +module AtPNotStmt; +proc main*; +var a: I64; +begin + a; +end; +end AtPNotStmt. diff --git a/test/err/AtPSetLit.err b/test/err/AtPSetLit.err new file mode 100644 index 0000000..221fe58 --- /dev/null +++ b/test/err/AtPSetLit.err @@ -0,0 +1,4 @@ +test/err/AtPSetLit.raz:6:14: error: not a name of C + 6 | s := {r, 1}; + | ^ +raz: 1 error diff --git a/test/err/AtPSetLit.raz b/test/err/AtPSetLit.raz new file mode 100644 index 0000000..68bc0a8 --- /dev/null +++ b/test/err/AtPSetLit.raz @@ -0,0 +1,8 @@ +module AtPSetLit; +type C = (r, g, b); +proc main*; +var s: set of C; +begin + s := {r, 1}; +end; +end AtPSetLit. diff --git a/test/err/AtPStep.err b/test/err/AtPStep.err new file mode 100644 index 0000000..578fc1c --- /dev/null +++ b/test/err/AtPStep.err @@ -0,0 +1,4 @@ +test/err/AtPStep.raz:5:24: error: the step can't be zero + 5 | for i := 1 to 5 by 1 - 1 do end; + | ^^^^^ +raz: 1 error diff --git a/test/err/AtPStep.raz b/test/err/AtPStep.raz new file mode 100644 index 0000000..96d4cf7 --- /dev/null +++ b/test/err/AtPStep.raz @@ -0,0 +1,7 @@ +module AtPStep; +proc main*; +var i: I64; +begin + for i := 1 to 5 by 1 - 1 do end; +end; +end AtPStep. diff --git a/test/err/AtPtrMinus.err b/test/err/AtPtrMinus.err new file mode 100644 index 0000000..5178f6d --- /dev/null +++ b/test/err/AtPtrMinus.err @@ -0,0 +1,4 @@ +test/err/AtPtrMinus.raz:5:10: error: different pointer types + 5 | x := p - q; + | ^^^^^ +raz: 1 error diff --git a/test/err/AtPtrMinus.raz b/test/err/AtPtrMinus.raz new file mode 100644 index 0000000..7f2b975 --- /dev/null +++ b/test/err/AtPtrMinus.raz @@ -0,0 +1,7 @@ +module AtPtrMinus; +proc main*; +var p: ^I64; q: ^I32; x: I64; +begin + x := p - q; +end; +end AtPtrMinus. diff --git a/test/err/AtReturn.err b/test/err/AtReturn.err new file mode 100644 index 0000000..5e11c92 --- /dev/null +++ b/test/err/AtReturn.err @@ -0,0 +1,4 @@ +test/err/AtReturn.raz:4:12: error: this procedure returns nothing + 4 | return 1 + 2; + | ^^^^^ +raz: 1 error diff --git a/test/err/AtReturn.raz b/test/err/AtReturn.raz new file mode 100644 index 0000000..503bab8 --- /dev/null +++ b/test/err/AtReturn.raz @@ -0,0 +1,6 @@ +module AtReturn; +proc main*; +begin + return 1 + 2; +end; +end AtReturn. diff --git a/test/err/AtSliceHi.err b/test/err/AtSliceHi.err new file mode 100644 index 0000000..8cbfba2 --- /dev/null +++ b/test/err/AtSliceHi.err @@ -0,0 +1,4 @@ +test/err/AtSliceHi.raz:5:15: error: an index is an integer + 5 | s := a[0..b]; + | ^ +raz: 1 error diff --git a/test/err/AtSliceHi.raz b/test/err/AtSliceHi.raz new file mode 100644 index 0000000..f743b53 --- /dev/null +++ b/test/err/AtSliceHi.raz @@ -0,0 +1,7 @@ +module AtSliceHi; +proc main*; +var a: [4]I64; b: BOOL; s: []I64; +begin + s := a[0..b]; +end; +end AtSliceHi. diff --git a/test/err/AtSliceLo.err b/test/err/AtSliceLo.err new file mode 100644 index 0000000..6ef2bac --- /dev/null +++ b/test/err/AtSliceLo.err @@ -0,0 +1,4 @@ +test/err/AtSliceLo.raz:5:12: error: an index is an integer + 5 | s := a[b..2]; + | ^ +raz: 1 error diff --git a/test/err/AtSliceLo.raz b/test/err/AtSliceLo.raz new file mode 100644 index 0000000..3ba4c17 --- /dev/null +++ b/test/err/AtSliceLo.raz @@ -0,0 +1,7 @@ +module AtSliceLo; +proc main*; +var a: [4]I64; b: BOOL; s: []I64; +begin + s := a[b..2]; +end; +end AtSliceLo. diff --git a/test/err/AtStrCmp.err b/test/err/AtStrCmp.err new file mode 100644 index 0000000..294ffec --- /dev/null +++ b/test/err/AtStrCmp.err @@ -0,0 +1,4 @@ +test/err/AtStrCmp.raz:5:12: error: can't compare a string with I64 + 5 | if s = x + 1 then end; + | ^^^^^ +raz: 1 error diff --git a/test/err/AtStrCmp.raz b/test/err/AtStrCmp.raz new file mode 100644 index 0000000..b26c2e2 --- /dev/null +++ b/test/err/AtStrCmp.raz @@ -0,0 +1,7 @@ +module AtStrCmp; +proc main*; +var s: []U8; x: I64; +begin + if s = x + 1 then end; +end; +end AtStrCmp. diff --git a/test/err/AtVarArg.err b/test/err/AtVarArg.err new file mode 100644 index 0000000..468fa0a --- /dev/null +++ b/test/err/AtVarArg.err @@ -0,0 +1,4 @@ +test/err/AtVarArg.raz:7:9: error: a var parameter needs a variable + 7 | Inc(1 + 2); + | ^^^^^ +raz: 1 error diff --git a/test/err/AtVarArg.raz b/test/err/AtVarArg.raz new file mode 100644 index 0000000..0daa2b5 --- /dev/null +++ b/test/err/AtVarArg.raz @@ -0,0 +1,9 @@ +module AtVarArg; +proc Inc(var a: I64); +begin a := a + 1; end; +proc main*; +var x: I64; +begin + Inc(1 + 2); +end; +end AtVarArg. diff --git a/test/err/BadProc.err b/test/err/BadProc.err index 10ad4a1..1e53284 100644 --- a/test/err/BadProc.err +++ b/test/err/BadProc.err @@ -1,4 +1,7 @@ -/home/luis/raz/lib/Map.raz:4:39: error: needs a procedure with the signature of hash +test/err/BadProc.raz:2:33: error: needs a procedure with the signature of hash + 2 | import Str, M := Map([]U8, I64, Str.cmp, Str.eq); + | ^^^^^^^ +lib/Map.raz:4:18: note: hash is declared here 4 | module Map(K, V; hash: proc(k: K): U64; eq: proc(a, b: K): BOOL); - | ^ + | ^^^^ raz: 1 error diff --git a/test/err/BigI64.err b/test/err/BigI64.err index fd08ea1..5bb5117 100644 --- a/test/err/BigI64.err +++ b/test/err/BigI64.err @@ -1,4 +1,4 @@ -test/err/BigI64.raz:5:28: error: can't use U64 as I64 +test/err/BigI64.raz:5:10: error: can't use U64 as I64 5 | i := 0FFFFFFFFFFFFFFFFH; - | ^ + | ^^^^^^^^^^^^^^^^^^ raz: 1 error diff --git a/test/err/Break.err b/test/err/Break.err index b925eb6..fc5ba00 100644 --- a/test/err/Break.err +++ b/test/err/Break.err @@ -1,4 +1,4 @@ -test/err/Break.raz:4:10: error: break outside a loop +test/err/Break.raz:4:5: error: break outside a loop 4 | break; - | ^ + | ^^^^^ raz: 1 error diff --git a/test/err/Cycle.err b/test/err/Cycle.err index bd9e32c..0d74639 100644 --- a/test/err/Cycle.err +++ b/test/err/Cycle.err @@ -1,4 +1,4 @@ -test/err/mods/CycleB.raz:2:13: error: Cycle imports itself +test/err/mods/CycleB.raz:2:8: error: Cycle imports itself 2 | import Cycle; - | ^ + | ^^^^^ raz: 1 error diff --git a/test/err/DeferBreak.err b/test/err/DeferBreak.err index 9188b80..7ea5da5 100644 --- a/test/err/DeferBreak.err +++ b/test/err/DeferBreak.err @@ -1,4 +1,4 @@ -test/err/DeferBreak.raz:5:20: error: break outside a loop +test/err/DeferBreak.raz:5:15: error: break outside a loop 5 | defer break; - | ^ + | ^^^^^ raz: 1 error diff --git a/test/err/DeferDefer.err b/test/err/DeferDefer.err index ba151df..b138329 100644 --- a/test/err/DeferDefer.err +++ b/test/err/DeferDefer.err @@ -1,4 +1,4 @@ -test/err/DeferDefer.raz:4:17: error: defer can't be deferred +test/err/DeferDefer.raz:4:11: error: defer can't be deferred 4 | defer defer f; - | ^ + | ^^^^^ raz: 1 error diff --git a/test/err/DeferReturn.err b/test/err/DeferReturn.err index 739bddd..e7c4fb0 100644 --- a/test/err/DeferReturn.err +++ b/test/err/DeferReturn.err @@ -1,4 +1,4 @@ -test/err/DeferReturn.raz:4:18: error: return can't leave a deferred statement +test/err/DeferReturn.raz:4:11: error: return can't leave a deferred statement 4 | defer return 1; - | ^ + | ^^^^^^ raz: 1 error diff --git a/test/err/ErrOrder.err b/test/err/ErrOrder.err index 45b2eda..323e235 100644 --- a/test/err/ErrOrder.err +++ b/test/err/ErrOrder.err @@ -1,4 +1,4 @@ -test/err/ErrOrder.raz:5:14: error: procedures and errors compare only with = and # +test/err/ErrOrder.raz:5:8: error: procedures and errors compare only with = and # 5 | if A < B then end; - | ^^^^ + | ^^^^^ raz: 1 error diff --git a/test/err/ExternRec.err b/test/err/ExternRec.err index 36db9af..c2e8f45 100644 --- a/test/err/ExternRec.err +++ b/test/err/ExternRec.err @@ -1,4 +1,4 @@ -test/err/ExternRec.raz:5:20: error: C takes integers, BOOL, reals, pointers and procedures +test/err/ExternRec.raz:5:13: error: C takes integers, BOOL, reals, pointers and procedures 5 | extern proc f(r: R); - | ^ + | ^ raz: 1 error diff --git a/test/err/F32Dots.err b/test/err/F32Dots.err index fd761dc..5040ac2 100644 --- a/test/err/F32Dots.err +++ b/test/err/F32Dots.err @@ -1,4 +1,4 @@ -test/err/F32Dots.raz:8:23: error: an F32 goes to ... as F64(x) +test/err/F32Dots.raz:8:22: error: an F32 goes to ... as F64(x) 8 | C.printf("%f\n", x); - | ^ + | ^ raz: 1 error diff --git a/test/err/Match.err b/test/err/Match.err index 19cc8e6..0a2778e 100644 --- a/test/err/Match.err +++ b/test/err/Match.err @@ -1,4 +1,4 @@ -test/err/Match.raz:9:8: error: no arm for c +test/err/Match.raz:9:5: error: no arm for c 9 | end; - | ^ + | ^^^ raz: 1 error diff --git a/test/err/Mixed.err b/test/err/Mixed.err index 8afa78e..a75acd8 100644 --- a/test/err/Mixed.err +++ b/test/err/Mixed.err @@ -1,4 +1,4 @@ -test/err/Mixed.raz:6:15: error: different types: F32 and F64 +test/err/Mixed.raz:6:10: error: different types: F32 and F64 6 | y := x + y; - | ^ + | ^^^^^ raz: 1 error diff --git a/test/err/NegU64.err b/test/err/NegU64.err index 5fea6b7..2882895 100644 --- a/test/err/NegU64.err +++ b/test/err/NegU64.err @@ -1,4 +1,4 @@ -test/err/NegU64.raz:5:12: error: constant doesn't fit U64 +test/err/NegU64.raz:5:10: error: constant doesn't fit U64 5 | u := -1; - | ^ + | ^^ raz: 1 error diff --git a/test/err/NoArgs.err b/test/err/NoArgs.err index f3f1253..237c8a1 100644 --- a/test/err/NoArgs.err +++ b/test/err/NoArgs.err @@ -1,4 +1,4 @@ -/home/luis/raz/lib/List.raz:2:13: error: needs a type for each type parameter - 2 | module List(T); - | ^ +test/err/NoArgs.raz:2:8: error: needs a type for each type parameter + 2 | import List; + | ^^^^ raz: 1 error diff --git a/test/err/NotGeneric.err b/test/err/NotGeneric.err index 1e9a919..694f964 100644 --- a/test/err/NotGeneric.err +++ b/test/err/NotGeneric.err @@ -1,4 +1,4 @@ -/home/luis/raz/lib/Str.raz:3:11: error: Str isn't generic - 3 | module Str; - | ^ +test/err/NotGeneric.raz:2:8: error: Str isn't generic + 2 | import S := Str(I64); + | ^^^^^^^^^^^^^ raz: 1 error diff --git a/test/err/PtrArray.err b/test/err/PtrArray.err index 0a4a351..a2fad5a 100644 --- a/test/err/PtrArray.err +++ b/test/err/PtrArray.err @@ -1,4 +1,4 @@ -test/err/PtrArray.raz:6:7: error: a pointer to an array is indexed as p^[i] +test/err/PtrArray.raz:6:5: error: a pointer to an array is indexed as p^[i] 6 | p[1] := 0; - | ^ + | ^ raz: 1 error diff --git a/test/err/Tuple.err b/test/err/Tuple.err index e8fa6e4..85c55a4 100644 --- a/test/err/Tuple.err +++ b/test/err/Tuple.err @@ -1,4 +1,4 @@ -test/err/Tuple.raz:6:16: error: several results go only to a, b := ... +test/err/Tuple.raz:6:10: error: several results go only to a, b := ... 6 | a := two() + 1; - | ^ + | ^^^^^ raz: 1 error diff --git a/test/err/TwoTypes.err b/test/err/TwoTypes.err index fc46b23..1ecd7b7 100644 --- a/test/err/TwoTypes.err +++ b/test/err/TwoTypes.err @@ -1,4 +1,4 @@ -test/err/TwoTypes.raz:6:11: error: can't use List(I32).List as List(I64).List +test/err/TwoTypes.raz:6:10: error: can't use List(I32).List as List(I64).List 6 | a := b; - | ^ + | ^ raz: 1 error diff --git a/test/err/Volatile.err b/test/err/Volatile.err index b47bcfb..def9ef4 100644 --- a/test/err/Volatile.err +++ b/test/err/Volatile.err @@ -1,4 +1,4 @@ -test/err/Volatile.raz:6:11: error: can't use ^VOLATILE I64 as ^I64 +test/err/Volatile.raz:6:10: error: can't use ^VOLATILE I64 as ^I64 6 | q := p; - | ^ + | ^ raz: 1 error