raz / commit 1107e80e

commit
1107e80e23a449b9889f57a6f2aecacb84ce6e99
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
f938aed4
Two messages mended: a generic module alone, a conversion dereferenced

A generic module compiled on its own blamed Rt.raz:1:1, where the
empty arguments said they were; now it says it is generic, at its
parameters. ^T(x)^ gave a type mismatch, and as a statement "expected
a statement" at the end of the line before; now each is a syntax
error at the ^, with help.

patch · log

7 files changed, +38 -1

src/parse.pas modified +9 -1

@@ -1115,6 +1115,9 @@
11151115 Expression(x, nil);
11161116 Expect(sRparen);
11171117 Convert(x, t);
1118+ { a conversion is a factor, not a designator: nothing selects from it }
1119+ if tok = sArrow then
1120+ MarkHelp(TokPos, 'a conversion can''t be dereferenced', 'convert into a pointer variable, then dereference that');
11181121 end;
11191122 else Expected('an expression');
11201123 end;
@@ -1789,6 +1792,7 @@
17891792 Jump(curLoop^.brk);
17901793 end;
17911794 sDefer: Defer;
1795+ sArrow: MarkHelp(TokPos, 'a statement starts with a name', 'convert into a pointer variable, then assign through that');
17921796 else if AtLineStart then EndMissing(MissingPos, 'expected "end", found ' + Found)
17931797 else Expected('a statement');
17941798 end;
@@ -2722,7 +2726,11 @@
27222726 Expect(sModule);
27232727 if (tok <> sIdent) or (id <> n) then Mark('expected module ' + NameOf(n) + ', found ' + Found);
27242728 Next;
2725- if tok = sLparen then Params(m)
2729+ { the module first pending is the one named on the command line,
2730+ which nothing imports, so no arguments come with it }
2731+ if (tok = sLparen) and not checkOnly and (numPending = 1) then
2732+ Mark(NameOf(n) + ' is generic: it is compiled where a module imports it')
2733+ else if tok = sLparen then Params(m)
27262734 else if args.n > 0 then MarkAt(args.at, NameOf(n) + ' isn''t generic');
27272735 Expect(sSemicolon);
27282736 while tok = sImport do begin

test/err/Alone.err (history) added +4 -0

@@ -0,0 +1,4 @@
1+test/err/Alone.raz:2:13: error: Alone is generic: it is compiled where a module imports it
2+ 2 | module Alone(T);
3+ | ^
4+raz: 1 error

test/err/Alone.raz (history) added +4 -0

@@ -0,0 +1,4 @@
1+(* A generic module, compiled on its own *)
2+module Alone(T);
3+var x: T;
4+end.

test/err/ConvDeref.err (history) added +5 -0

@@ -0,0 +1,5 @@
1+test/err/ConvDeref.raz:4:15: error: a conversion can't be dereferenced
2+ 4 | b := ^INT(a)^
3+ | ^
4+help: convert into a pointer variable, then dereference that
5+raz: 1 error

test/err/ConvDeref.raz (history) added +5 -0

@@ -0,0 +1,5 @@
1+module ConvDeref;
2+var a, b: INT;
3+begin
4+ b := ^INT(a)^
5+end.

test/err/ConvStatement.err (history) added +5 -0

@@ -0,0 +1,5 @@
1+test/err/ConvStatement.raz:5:3: error: a statement starts with a name
2+ 5 | ^INT(a)^ := 1
3+ | ^
4+help: convert into a pointer variable, then assign through that
5+raz: 1 error

test/err/ConvStatement.raz (history) added +6 -0

@@ -0,0 +1,6 @@
1+module ConvStatement;
2+var a: INT;
3+begin
4+ a := 1;
5+ ^INT(a)^ := 1
6+end.