[fpc-pascal] Class field property access

Michael Van Canneyt michael at freepascal.org
Fri Jun 7 08:51:58 CEST 2019



On Thu, 6 Jun 2019, Ryan Joseph wrote:

>
>
>> On Jun 3, 2019, at 11:13 AM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>> 
>> The b field could be Nil and the class might not provide any functionality to check for that. In addition to that it's an additional indirection while records/objects merely require an offset. 
>> 
>
> { I’ve resubscribed to the list with a new email since the mail server wasn’t liking my old one. Resending this message since it was rejected before. }
>
> But my point is Pascal allows this kind of behavior so why are properties
> different?

What kind of behaviour are you referring to.

> Who cares if there is an additional level of indirection?

Because the indirection may not be there. 
The compiler cannot guarantee that, thus leading to access violations.

You can use a getter function to get the desired property. In the getter you
can decide what to do: create the b instance (sometimes a valid choice) 
or raise an error.

But the compiler cannot take this decision for you, so b.x is not allowed.

> This appears to be a regression since 3.0.4 also.  Did you specifically
> disable this in 3.3.1?  Sorry I’m not understanding this one.

If it was allowed in previous versions, this was by accident allowed during
parsing and most likely simply didn't work in reality.

Michael.


More information about the fpc-pascal mailing list