Discussion Thread: DIP 1030--Named Arguments--Final Review

jmh530 john.michael.hall at gmail.com
Thu May 14 13:20:36 UTC 2020


On Thursday, 14 May 2020 at 12:03:13 UTC, Petar Kirov 
[ZombineDev] wrote:
> [snip]
>
> [1]:
> /sandbox/main.d(5): Error: `library.copy` called with argument 
> types `(string, string)` matches both:
> /sandbox/library.d(1):     `library.copy(string source, string 
> destination)`
> and:
> /sandbox/library.d(7):     `library.copy(string source, string 
> distinasion)`

Interesting that it only mentions two of them and not all of 
them. If you comment one of them out, then it mentions the other.

To your suggestion above, it's unclear if you are suggesting that 
the compiler read the deprecation message and change behavior 
somehow based on it. There is nothing stopping you from providing 
detailed deprecation messages today. Expanding on Seb's example, 
you could have something like below.

void foo(int x, int y) { ... }

deprecated("Parameters renamed: `xVal` -> `x` | `yVal` -> `y`")
extern(D, argNames)
void foo(int xVal, int yVal) { ... }

The extern(D, argNames) is from Seb and is what would tell the 
compiler to only allow calling foo with keyword arguments.

Thinking on it, you could make this even more general and have
extern(D, positionOnly)
extern(D, keywordOnly)
which would force either positionOnly or keywordOnly syntax. That 
would resolve any concerns that I have.


More information about the Digitalmars-d mailing list