Deprecate typesafe variadic class arguments (#20673)

This commit is contained in:
Dennis 2025-02-16 21:35:11 +01:00 committed by GitHub
parent 0131a00173
commit 961862c455
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 53 additions and 50 deletions

View 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"));
}
---