DIP 1030--Named Arguments--Community Review Round 1 Feedback

Steven Schveighoffer schveiguy at gmail.com
Fri Feb 7 15:49:53 UTC 2020


On 2/6/20 1:09 AM, Mike Parker wrote:
> This is the feedback thread for the first round of Community Review of 
> DIP 1030, "Named Arguments".

Some thoughts on the variadic matching:

---
5. If there are more NamedArguments than Parameters, the remainder match 
the trailing ... of variadic parameter lists, and Identifiers are not 
allowed.

---

What happens here?

template foo(T...) {}

foo!(T: 1, 2, 3);

I think it should compile and the result should be foo!(1, 2, 3)

Same thing for something like:

void foo(int[] arr...)

foo(arr: 1, 2, 3)

----

Regarding only matching if there are more named arguments than 
parameters, I think this needs rewording. According to that description, 
what happens on these calls?

void foo(int a, int b, ...)

foo(b: 1, a: 2, 3, 4, 5)

According to rule 2, the argument 3 should match b. But according to 
rule 5, it should match the variadic parameters.

Another case:

foo(b:1, 2, 3, a:4, 5, 6)

---

my recommendation is that rule 5 be reworded like:

"If an identifier is not present, and the parameter being selected by 
rule 2 is the trailing variadic `...`, then the argument is added to the 
variadic arguments of the function."

And add rule 6:

"If an identifier matches a variadic template parameter name, or a type 
safe variadic parameter name, then that argument becomes the first 
element in the variadic match. Any subsequent parameters without 
identifiers match the trailing `...`. You cannot match a variadic by 
name more than once."

-Steve


More information about the Digitalmars-d mailing list