[fpc-pascal] with in classes/records

Sven Barth pascaldragon at googlemail.com
Tue Sep 4 14:15:00 CEST 2018


Ryan Joseph <ryan at thealchemistguild.com> schrieb am Di., 4. Sep. 2018,
11:27:

>
>
> > On Sep 4, 2018, at 2:06 PM, Ryan Joseph <ryan at thealchemistguild.com>
> wrote:
> >
> > Sorry I didn’t think enough before I sent this.
> >
> > We *must* allow this assignment to make operator overloads work. +=
> operators are also basically assigning TWrapper to TWrapper, right? I guess
> we need to break the default property behavior is instances that the same
> type is being assigned to itself but correct me if I’m wrong.
> >
> > var
> >       wrapper: TWrapper;
> >
> > wrapper += 10;
>
> Some questions about operator overloads.
>
> 1) rec := 1; should resolve to rec.num := 1 obviously.
>
> 2) rec += 10; should call the function TWrapper.+ right? It could operate
> directly on the field “num” but then the actual function wouldn’t be called.
>

Would you please stop thinking with the C operators? They are merely
syntactic sugar and they don't exist by themselves. For this topic at least
please stick to their full versions (in your example "rec := rec + 10") as
that highlights better what the compiler needs to handle. In this case both
the + *and* the assignment operator.


> 3) should writeln(rec); resolve to writeln(rec.num); or be a syntax error?
> If it resolves to rec.num then passing around the record would technically
> just pass the num field and not the record. That doesn’t sound right to me.
> Without thinking about it much it feels like “rec” in isolation should be
> treated as the base type, ie. TWrapper.
>
> 4) I guess := operator overloads for records with a default property
> should be disabled, right? Otherwise they present a conflict that needs to
> be resolved.
>

The idea of the default property is that *all* operators (and methods)
(except management operators) are hoisted from the type of the default
property. The assignment of one record with default property to another of
the same type is handled by the Copy management operator.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180904/d5141818/attachment.html>


More information about the fpc-pascal mailing list