From 1107e80e23a449b9889f57a6f2aecacb84ce6e99 Mon Sep 17 00:00:00 2001 From: Luis <42945842+ldiaz94@users.noreply.github.com> Date: Tue, 13 Oct 2026 10:37:44 +0100 Subject: [PATCH] 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. --- diff --git a/src/parse.pas b/src/parse.pas index 03324fb..6285b19 100644 --- a/src/parse.pas +++ b/src/parse.pas @@ -1115,6 +1115,9 @@ Expression(x, nil); Expect(sRparen); Convert(x, t); + { a conversion is a factor, not a designator: nothing selects from it } + if tok = sArrow then + MarkHelp(TokPos, 'a conversion can''t be dereferenced', 'convert into a pointer variable, then dereference that'); end; else Expected('an expression'); end; @@ -1789,6 +1792,7 @@ Jump(curLoop^.brk); end; sDefer: Defer; + sArrow: MarkHelp(TokPos, 'a statement starts with a name', 'convert into a pointer variable, then assign through that'); else if AtLineStart then EndMissing(MissingPos, 'expected "end", found ' + Found) else Expected('a statement'); end; @@ -2722,7 +2726,11 @@ Expect(sModule); if (tok <> sIdent) or (id <> n) then Mark('expected module ' + NameOf(n) + ', found ' + Found); Next; - if tok = sLparen then Params(m) + { the module first pending is the one named on the command line, + which nothing imports, so no arguments come with it } + if (tok = sLparen) and not checkOnly and (numPending = 1) then + Mark(NameOf(n) + ' is generic: it is compiled where a module imports it') + else if tok = sLparen then Params(m) else if args.n > 0 then MarkAt(args.at, NameOf(n) + ' isn''t generic'); Expect(sSemicolon); while tok = sImport do begin diff --git a/test/err/Alone.err b/test/err/Alone.err new file mode 100644 index 0000000..4f92a04 --- /dev/null +++ b/test/err/Alone.err @@ -0,0 +1,4 @@ +test/err/Alone.raz:2:13: error: Alone is generic: it is compiled where a module imports it + 2 | module Alone(T); + | ^ +raz: 1 error diff --git a/test/err/Alone.raz b/test/err/Alone.raz new file mode 100644 index 0000000..4c93776 --- /dev/null +++ b/test/err/Alone.raz @@ -0,0 +1,4 @@ +(* A generic module, compiled on its own *) +module Alone(T); +var x: T; +end. diff --git a/test/err/ConvDeref.err b/test/err/ConvDeref.err new file mode 100644 index 0000000..fdcd98d --- /dev/null +++ b/test/err/ConvDeref.err @@ -0,0 +1,5 @@ +test/err/ConvDeref.raz:4:15: error: a conversion can't be dereferenced + 4 | b := ^INT(a)^ + | ^ +help: convert into a pointer variable, then dereference that +raz: 1 error diff --git a/test/err/ConvDeref.raz b/test/err/ConvDeref.raz new file mode 100644 index 0000000..f730e69 --- /dev/null +++ b/test/err/ConvDeref.raz @@ -0,0 +1,5 @@ +module ConvDeref; +var a, b: INT; +begin + b := ^INT(a)^ +end. diff --git a/test/err/ConvStatement.err b/test/err/ConvStatement.err new file mode 100644 index 0000000..13e5b3a --- /dev/null +++ b/test/err/ConvStatement.err @@ -0,0 +1,5 @@ +test/err/ConvStatement.raz:5:3: error: a statement starts with a name + 5 | ^INT(a)^ := 1 + | ^ +help: convert into a pointer variable, then assign through that +raz: 1 error diff --git a/test/err/ConvStatement.raz b/test/err/ConvStatement.raz new file mode 100644 index 0000000..ab2edd6 --- /dev/null +++ b/test/err/ConvStatement.raz @@ -0,0 +1,6 @@ +module ConvStatement; +var a: INT; +begin + a := 1; + ^INT(a)^ := 1 +end.