[fpc-devel] [] property overloads

Michael Van Canneyt michael at freepascal.org
Mon Jul 1 23:25:19 CEST 2019



On Mon, 1 Jul 2019, Ondrej Pokorny wrote:

> On 01.07.2019 21:04, Michael Van Canneyt wrote:
>> On Mon, 1 Jul 2019, Ondrej Pokorny wrote:
>>> On 01.07.2019 19:38, Michael Van Canneyt wrote:
>>>> On Mon, 1 Jul 2019, Ondrej Pokorny wrote:
>>>>> On 01.07.2019 18:21, Michael Van Canneyt wrote:
>>>>>> On Mon, 1 Jul 2019, Ondrej Pokorny wrote:
>>>>>> From the above example "Mytest.StringArray" can only evaluate to 
>>>>>> TTestObjectEnumerator. Nothing else.
>>>>
>>>> Well, this is IMHO not correct. The array is also a possibility.
>>>>
>>>> The compiler encounters Mytest.StringArray - at that point he has 2
>>>> possibilities. It's an array (and an index must expected) or it is an
>>>> enumerator (and nothing must be expected), but at this point the 
>>>> compiler
>>>> cannot decide without looking at the context.
>>>
>>> There is no array. "property StringArray[Index: Integer]" is not an 
>>> array and cannot be evaluated as an array.
>>
>> Please, you know what I mean... It is an "array property".
>
> Sorry - I didn't mean it bad/ironic/whatsoever. I just thought you meant 
> that:
>
> MyArray := Mytest.StringArray;
>
> might be a valid assignment for
>
>   TTest = class
>   public
>     property StringArray[Index: Integer]: string read GetString;
>   end;
>   TMyArray = array of string;
>
> If it was a valid assignment, there would be 2 possibilities indeed and 
> the compiler would need to check the left side to resolve the overload:
>
> MyArray := Mytest.StringArray;
> MyEnumerator := Mytest.StringArray;
>
> But such syntax is invalid for indexed (array) properties.

I understand. But all depends on how the compiler parses and evaluates this.

Let me put brackets to make it more clear: is

MyTest.StringArray[i]

parsed & evaluated as

(MyTest.StringArray)([(i)])

or as

(MyTest.StringArray[(i)])

In the former case, the compiler cannot know what the result type is of the
first set of brackets in your proposal. In the latter case, it can be OK.

But I simply do not know, someone with more intimate knowledge of the
compiler needs to shed light on this.

Michael.


More information about the fpc-devel mailing list