[fpc-pascal] Optional param modifier

Martin Frb lazarus at mfriebe.de
Mon Apr 15 00:04:14 CEST 2019

On 14/04/2019 23:48, Martin Frb wrote:
> I admit the contract/assert stuff may have made it seem different. But 
> that is because this approach does not hold up (IMHO). And therefore 
> the closest alternative was presented.
> In the very end it is to avoid crashing on nil de-ref. And the 
> contract/assert can help there. Though in a completely different way.

The contract actually can lead to the thing you want. Though you need to 
complete it for *all* your code, rather than just one or two functions

If/Once you have your entire code base with contracts, you know that any 
method/function that does not have a "assigned" contract, can return nil 
(i.e. nil is a documented expected return value / or input )

So at that time, you can enable a compiler warning of the kind you 
wanted. It would act on all the params/results that per contract can be 
nil (are not forbidden to be nil).

The only thing you do not have, is the undefined bit. The it can return 
nil, but I do not want to check it.
If you really want that, there will be a directive like {$PUSH}{$R-} 
.... {$POP}.

More information about the fpc-pascal mailing list