mirror of
https://github.com/dlang/dmd.git
synced 2025-04-25 20:50:41 +03:00
Deprecate typesafe variadic class arguments (#20673)
This commit is contained in:
parent
0131a00173
commit
961862c455
5 changed files with 53 additions and 50 deletions
40
changelog/dmd.deprecation-typesafe-variadic-class.dd
Normal file
40
changelog/dmd.deprecation-typesafe-variadic-class.dd
Normal file
|
@ -0,0 +1,40 @@
|
|||
Typesafe variadic class parameters have been deprecated
|
||||
|
||||
This obscure feature allowed a limited form of implicit construction:
|
||||
|
||||
---
|
||||
void check(bool x, Exception e...)
|
||||
{
|
||||
if (!x)
|
||||
throw e;
|
||||
}
|
||||
|
||||
void main(string[] args)
|
||||
{
|
||||
check(args.length > 1, "missing argument");
|
||||
}
|
||||
---
|
||||
|
||||
However, few uses of this feature have been found, and one project was actually mistakenly using it instead of the more common Typesafe variadic array parameter.
|
||||
Considering D doesn't support implicit construction and already has a confusing amount of different variadic parameter forms, it was decided to remove this feature.
|
||||
|
||||
As a corrective action, either call the constructor in the callee:
|
||||
|
||||
---
|
||||
void check(string msg)
|
||||
{
|
||||
if (!x)
|
||||
throw new Exception(msg);
|
||||
}
|
||||
---
|
||||
|
||||
Or let the caller construct the class instance:
|
||||
|
||||
---
|
||||
void check(bool x, Exception e);
|
||||
|
||||
void main(string[] args)
|
||||
{
|
||||
check(args.length > 1, new Exception("missing argument"));
|
||||
}
|
||||
---
|
Loading…
Add table
Add a link
Reference in a new issue