[fpc-devel] Proof of Concept ARC implementation

hinstance at yandex.ru hinstance at yandex.ru
Wed Oct 29 15:56:50 CET 2014


Whatever; I disagree
refcounted descendants of non-refcounted objects should be assignable to any variable of parent type; just like any variable is assignable to a variable of parent type

type
  TRefc = class refcounted(TObject) 
  end;

var
  thing: TObject;
  refThing: TRefc;
begin
  ...
  thing := refThing;  // fine because TRefc is TObject
  refThing := thing;  // compiler refuses because thing is not necessarily refThing
  refThing := TRefc(thing); // fine; explicit casting

and that is my vision of how this should work

however mandatory explicit casting is also a viable option:

thing := TObject(refThing);  // okay, compiler, I know what I'm doing, now do your thing, cast this for me


29.10.2014, 17:46, "Jonas Maebe" <jonas.maebe at elis.ugent.be>:
> On 29 Oct 2014, at 15:09, hinstance at yandex.ru wrote:
>>  With lists it's worse. If you store pointers to interface variables,
>>  they become invalid the moment you don't have any "managed"
>>  variables left in scope.
>>
>>  Same is true for refcounted objects: if you store them in good old
>>  TObjectList, it will hold invalid pointers.
>>
>>  However this all is just something to keep in mind. I don't see the
>>  need of overcomplicating it on compiler level
>
> It's not "just something to keep in mind", because if you include
> automatic conversion from ref-counted to non-refcounted classes, this
> is guaranteed to lead to very hard to debug problems. One of Pascal's
> foundations is that it has strong type checking and does not allow you
> to assign anything to anything just because it happens to have the
> same size in bits and somewhat similar functionality. You cannot
> assign an interface to a class instance without explicitly using "as"
> either.
>
> Jonas
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel



More information about the fpc-devel mailing list