On 14/04/2019 18:04, Martin Frb wrote:
On 14/04/2019 16:05, Ryan Joseph wrote:
On Apr 14, 2019, at 3:15 AM, Sven Barth via fpc-pascal <fpc-pascal@lists.freepascal.org> wrote:

Your idea requires exceptions as well. The compiler is not capable checking whether valid entries are passed in at compile time except for simple, constant cases, so runtime checks are needed and the only way to abort something is by exceptions.
My idea didn’t require the procedure to exit so I don’t see where an exception would be needed. It just says if a param was flagged you would need to check for nil before dereferencing other you get a compile time error.
First of all the max you should get is a note (warning, maybe). But never a compile time error.
As for your feature of getting a note from the compiler, if you deref a param (or other variable) that according to the compilers awareness could be nil at the time.

There is on need to say "optional".
Technically any nil-able var could be nil. So the compiler note should be for any such variable. Exactly like currently the "variable not initialized".

The downside: That would flood current code with compiler-notes. Because any param could be nil, even if the programmer has documented somewhere that this is not allowed.

But if pre-conditions where available, this could be combined.
The compiler could assume that if you wrote pre-conditions for a method, and that if you did non add "foo <> nil" to those conditions, then you expect that foo can be nil. And in that case the compiler could add appropriate notes, if it finds you do not check for nil.

Existing code has no pre-conditions and is not affected. New code then must contain this.

Or the warning could apply to all code, but by default is not generated. You can enable it for each unit via commandline switch or directive. Again no "optional" needed.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to