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

Yury Sidorov jura at cp-lab.com
Thu Sep 18 15:06:26 CEST 2008


From: "Florian Klaempfl" <florian at freepascal.org>
> Yury Sidorov schrieb:
>> From: "Florian Klaempfl" <florian at freepascal.org>
>>> Michael Van Canneyt schrieb:
>>>>
>>>> On Thu, 18 Sep 2008, Graeme Geldenhuys wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>> I was following a discussion in the delphi.non-technical 
>>>>> newsgroup.
>>>>> They raised an issue about distinct types. I tried the following
>>>>> example under FPC and unexpectedly, FPC doesn't raise any 
>>>>> errors!
>>>>>
>>>>> If you declare a distinct type as follows:
>>>>>   type TMyInteger = type Integer;
>>>>>
>>>>> 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.
>>>>
>>>> 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.
>>>
>>> This is not true. The main purpose is to be able to overload 
>>> functions/operators:
>>>
>>> type
>>>   TUTF8String = type ansistring;
>>>
>>> enables you to overload all procedure already defined for 
>>> ansistrings with UTF8String functions but reusing ansistring 
>>> support functionality and this is supported for years. Because 
>>> nobody used this yet to make an utf-8 unit, I never took the 
>>> unicode string support serious :)
>>
>> Yes. But it works only partially. For example the following code is 
>> not compilable:
>
> Well, I wouldn't know either what you expect :)

I expect that compiler will choose DoTest with ansistring parameter in 
that case.

>> //------
>> type
>>  TUTF8String = type ansistring;
>>
>> procedure DoTest(const s: ansistring); overload;
>> begin
>> end;
>>
>> procedure DoTest(const s: TUTF8String); overload;
>> begin
>> end;
>>
>> begin
>>  DoTest('1234');
>> end.
>>
>> //------



More information about the fpc-devel mailing list