[fpc-pascal] Optional param modifier

Sven Barth pascaldragon at googlemail.com
Sun Apr 14 00:01:48 CEST 2019

On 4/13/19 11:39 PM, Martin Frb wrote:
> On 13/04/2019 23:17, Ryan Joseph wrote:
>> If there was any other way the compiler could make this contract more
>> concrete and reliable then comments I’d be happy to hear it.
> I don't know what others think of it, but
> https://en.wikipedia.org/wiki/Design_by_contract
> look at pre/post-conditions.
> It basically is like assertions. But it is a bit more, because there are
> rules for inheritance. So it should be part of the declaration, not the
> implementation.
> Once such conditions exists, the compiler could be enhanced in different
> ways:
> - insert the correct assertions
> - check at compile time, if possible (may give errors, warnings, hints,
> depending how certain the compiler is)
> Of course it does a bit of the opposite of what you did. It allows to
> say, when a param is not allowed nil.
> By implication any param that has no pre-condition is allowed nil, and
> the compiler should assume it may be nil.

Well, there is Oxygene's concept of Class Contracts (see
https://docs.elementscompiler.com/Concepts/ClassContracts/ ), so if
anything in that direction would be done I'd be inclined towards their
syntax (and I've played with the idea to implement this in FPC for quite
some time already).

Though of course it wouldn't necessarily solve the point of knowing
whether one may pass Nil or not, cause especially in compiled code you
can't look at the source. So the compiler would need to store the
conditions in the PPU as well, so that the IDE could present them as
part of the tooltip even if no source is available...


More information about the fpc-pascal mailing list