[fpc-devel] [] property overloads

Michael Van Canneyt michael at freepascal.org
Mon Jul 1 18:21:55 CEST 2019



On Mon, 1 Jul 2019, Ondrej Pokorny wrote:

> On 01.07.2019 15:57, Ryan Joseph wrote:
>> Yes, I’ve made a patch to allow overriding the actual property 
> (https://bugs.freepascal.org/view.php?id=35772).
>
> Very good! Just a short question: does your solution allow one overload 
> without array indexes? It is very useful as a for-in enumerator of the 
> array property:
>
>   TTest = class
>   public
>     // ...
>     property StringArray[Index: Integer]: string read GetString;
>     property StringArray: TTestObjectEnumerator read GetString;
>   end;

I really don't think this should be allowed. You can perfectly do

property EnumStringArray: TTestObjectEnumerator read GetString;

For S in Mytest.EnumStringArray

Typing this extra letters is not going to hurt.

Your proposal violates the rule that the resulting type of an expression must be known when evaluating it.

with
   Mytest.StringArray
it is not clear what the Mytest.StringArray should evaluate to.

It can be 2 things:

- An array, in which case an index is needed.
- An enumerator.

The compiler does not know what to choose, except by looking at the context and that is definitely not OK.

Michael.


More information about the fpc-devel mailing list