What to do about default function arguments

Timon Gehr timon.gehr at gmx.ch
Thu Apr 26 03:16:39 PDT 2012


On 04/26/2012 11:54 AM, Don Clugston wrote:
> On 26/04/12 11:21, Timon Gehr wrote:
>> On 04/26/2012 09:54 AM, Walter Bright wrote:
>>> On 4/26/2012 12:47 AM, Timon Gehr wrote:
>>>> On 04/26/2012 05:44 AM, Walter Bright wrote:
>>>>> A subtle but nasty problem - are default arguments part of the
>>>>> type, or
>>>>> part of the declaration?
>>>>>
>>>>> See http://d.puremagic.com/issues/show_bug.cgi?id=3866
>>>>>
>>>>> Currently, they are both,
>>>>
>>>> That is how it should be.
>>>>
>>>>> which leads to the nasty behavior in the bug report.
>>>>>
>>>>
>>>> It contributes, but it is not the main cause.
>>>>
>>>>> The problem centers around name mangling. If two types mangle the
>>>>> same,
>>>>> then they are the same type.
>>>>
>>>> Then they are equal types.
>>>
>>> This is simply not tenable. What defines when they are "equal" types and
>>> when they are "not equal"?
>>
>> This is a matter of terminology. For example, for 'equal' just exclude
>> the default parameters from the comparison. For 'the same' include
>> default parameters in the comparison. (therefore, 'the same' implies
>> 'equal')
>
> The language doesn't have the concepts of "same" and "equal" with
> respect to types. There is "equal" and "implicitly converts to", but
> that's not quite the same.
>
>>>> The schizophrenic behavior occurs because the types cross-talk. Are
>>>> mangled
>>>> names kept unique in the compiler or what is the implementation issue
>>>> exactly?
>>>
>>> It's a conceptual issue. When is one type the same as another, and when
>>> is it not?
>>>
>>
>> void function(int) is the same as void function(int) and both are equal
>> void function(int=2) is not the same as void function(int=3), but both
>> are equal.
>
> The question was *when* are they same, not how you name them.

I think I have answered that. Anyway, probably it is indeed a good idea 
to get rid of default parameters for delegates and function pointers.
The issues are certainly resolvable but the complexity of the resulting 
feature could not be justified.


More information about the Digitalmars-d mailing list