DIP 1020--Named Parameters--Community Review Round 2
a11e99z
black80 at bk.ru
Thu Sep 12 12:15:57 UTC 2019
On Thursday, 12 September 2019 at 11:46:46 UTC, rikki cattermole
wrote:
> On 12/09/2019 11:29 PM, Yuxuan Shui wrote:
>> Dumb question: @named parameters are ignored in overload
>> resolution, so in this example:
>>
>> void draw(@named Circle shape);
>> void draw(@named Rectangle shape);
>>
>> Is a call to draw:
>>
>> draw(someShape);
>>
>> always going to be a compilation error?
>
> Yes.
> Because you didn't use a named argument.
wait!
why should be error here?
when named args doesn't set - use usual overload rules.
> void draw( @named Rect rect );
> void draw( @named Circle oval );
> Shape shape = Line( ... ); // can be Rect/Circle too with same
> result
> Rect oval = Rect( ... );
> Circle rect = Circle( ... );
> draw( shape ); // ERROR. no method for Shape
> draw( rect ); // OK. draw( Circle <- rect ). rect is Circle in
> my case
> draw( oval ); // OK. draw( Rect <- oval ).
> draw( oval: shape ); // ERROR: struct/class Shape is not good
> for any overloads
> draw( oval: oval ); // ERROR: oval is Rect and no named arg
> "oval" for method that receive Rect.
> draw( oval: rect ); // OK. draw( Circle <- rect )
> draw( rect: shape ); // ERROR. No overloads for Shape
> draw( rect: rect ); // ERROR. rect is Circle and method draw(
> Circle ) doens't have arg "rect"
> draw( rect: oval ); // OK. draw( Rect <- oval );
More information about the Digitalmars-d
mailing list