[fpc-devel] Bug in FPC and declaring distinct types

Michael Van Canneyt michael at freepascal.org
Thu Sep 18 10:11:50 CEST 2008



On Thu, 18 Sep 2008, Graeme Geldenhuys wrote:

> On Thu, Sep 18, 2008 at 9:42 AM, Michael Van Canneyt
> <michael at freepascal.org> wrote:
> >>
> >> The type TMyInteger <> Integer so you are not supposed to be allowed
> >> to assign one to the other. Yet you can. See the following program.
> >
> > But obviously delphi also allows it ? It compiles everything,
> > just not as a var parameter.
> 
> Which still doesn't discount it as a bug in both FPC and Delphi!  At
> least in Delphi it fails on the var parameter, so it's 50% there - it
> should really fail on both counts.  You are not allowed to do that
> (assign different types) with any other types, so why allow it with
> custom made types??
> 
> 
> > The whole 'Type' thing is a bit ridiculous: the only reason they did it
> > is so they can have different type pointers in the RTTI for something which
> > is the same 'type' anyway. For the rest it is extremely badly designed,
> > and not really consistent. It serves no purpose. FPC introduced it to
> > be able to compile Delphi code, no other reason.
> 
> I'm not going to get into the whole argument about the usefulness of
> distinct types - for that you can read the thread posted in
> delphi.non-technical titled: "Generics. How can I?" dated 2008-09-15
> 
> All I can say, is that distinct types (custom made types) are used all
> over the place, in Delphi, Lazarus, fpGUI and I'm pretty sure FPC as
> well. It's a handy language feature and should allow type safety like
> all other types.

And it is also very annoying because

Type
  MyString = type string;

Const
  AString = 'something';

Var
  M : MyString;

begin
  M:=AString;
end.

Will no longer compile if you are too strict. They should at least remain 
assignment compatible. Delphi does the best it can, FPC should maybe be
a bit more strict - it should not allow the var parameter.

Michael.



More information about the fpc-devel mailing list