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

@ -2493,10 +2493,17 @@ Type typeSemantic(Type type, Loc loc, Scope* sc)
errors = true;
}
const bool isTypesafeVariadic = i + 1 == dim &&
tf.parameterList.varargs == VarArg.typesafe &&
(t.isTypeDArray() || t.isTypeClass());
if (isTypesafeVariadic)
const bool isTypesafeVariadic = i + 1 == dim && tf.parameterList.varargs == VarArg.typesafe;
const bool isStackAllocatedVariadic = isTypesafeVariadic && (t.isTypeDArray() || t.isTypeClass());
if (isTypesafeVariadic && t.isTypeClass())
{
// Deprecated in 2.111, kept as a legacy feature for compatibility (currently no plan to turn it into an error)
.deprecation(loc, "typesafe variadic parameters with a `class` type (`%s %s...`) are deprecated",
t.isTypeClass().sym.ident.toChars(), fparam.toChars());
}
if (isStackAllocatedVariadic)
{
/* typesafe variadic arguments are constructed on the stack, so must be `scope`
*/
@ -2518,7 +2525,7 @@ Type typeSemantic(Type type, Loc loc, Scope* sc)
}
}
if (isTypesafeVariadic)
if (isStackAllocatedVariadic)
{
/* This is because they can be constructed on the stack
* https://dlang.org/spec/function.html#typesafe_variadic_functions