Am 08.05.2021 um 19:38 schrieb Ryan Joseph via fpc-devel:

On May 8, 2021, at 11:18 AM, Sven Barth <> wrote:

It's not about reference counted classes vs. managed records, but about whether 
it's *per type* or *per variable*, the implementation details are completely 
irrelevant for now.
So the biggest concern you see if that classes are easier to assign to 
non-reference counted classes? The only difference between classes and records 
in this regard is that records give errors unless you assign directly to the 
same record type, where classes can be assigned to super-classes which may not 
be managed.

As you say there would need to be at least a warning if you cast a managed 
class to another class type or make it forbidden completely. I don't see that 
as a deal breaker personally but you seem to feel pretty strongly about it.

It seems that you don't work much with classes then. If one disallows the assignment of a reference counted class to a non-reference counted one then you can't use e.g. TStringList.Objects. There is also the problem of method pointers, which essentially only have a Pointer as Self data. Also a reference might escape in a parent class (for this example I'll use the syntax I used in my branch):

=== code begin ===

{$mode objfpc}

  TTest = class
    procedure DoSomething;

  TTestSub = class refcounted(TTest)
    procedure Test;

procedure TTest.DoSomething;
  // maybe this functions stores the reference

procedure TTest.Test;

=== code end ===

Obviously these problems won't be solved with the alternative approach either, but likely one can make clear more easily that the use case is for local instances.

Anyways I wrote up a little wiki with some potential implementation notes about a default 
property (which overlaps on the "defaults implements" as traits stuff). Important 
points are restricting what types can be default properties (classes and maybe/probably 
typed pointers) and limiting hoisting to subscripting, so it's kind of like the -> 
operator overload in C++.
It shouldn't hoist only public members, it should hoist according to the visibility rules (thus the hoisting depends on the callsite), otherwise it won't behave like Pascal classes do and thus we can forget it right away.

fpc-devel maillist  -

Reply via email to