DIP 1020--Named Parameters--Community Review Round 2
black80 at bk.ru
Thu Sep 12 12:15:57 UTC 2019
On Thursday, 12 September 2019 at 11:46:46 UTC, rikki cattermole
> 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:
>> always going to be a compilation error?
> Because you didn't use a named argument.
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
> 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