mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 21:21:48 +03:00
escape.d: Fix handling of isTypesafeVariadicArray (#16709)
This commit is contained in:
parent
6b49d066a2
commit
f158c3553e
3 changed files with 10 additions and 19 deletions
|
@ -1215,7 +1215,13 @@ private bool checkReturnEscapeImpl(ref Scope sc, Expression e, bool refs, bool g
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v.isScope())
|
if (v.isTypesafeVariadicArray && p == sc.func)
|
||||||
|
{
|
||||||
|
if (!gag)
|
||||||
|
sc.eSink.error(e.loc, "returning `%s` escapes a reference to variadic parameter `%s`", e.toChars(), v.toChars());
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
else if (v.isScope())
|
||||||
{
|
{
|
||||||
/* If `return scope` applies to v.
|
/* If `return scope` applies to v.
|
||||||
*/
|
*/
|
||||||
|
@ -1270,12 +1276,6 @@ private bool checkReturnEscapeImpl(ref Scope sc, Expression e, bool refs, bool g
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (v.isTypesafeVariadicArray && p == sc.func)
|
|
||||||
{
|
|
||||||
if (!gag)
|
|
||||||
sc.eSink.error(e.loc, "returning `%s` escapes a reference to variadic parameter `%s`", e.toChars(), v.toChars());
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//printf("no infer for %s in %s, %d\n", v.toChars(), sc.func.ident.toChars(), __LINE__);
|
//printf("no infer for %s in %s, %d\n", v.toChars(), sc.func.ident.toChars(), __LINE__);
|
||||||
|
@ -2023,15 +2023,6 @@ void escapeByRef(Expression e, ref scope EscapeByResults er, bool retRefTransiti
|
||||||
void visitIndex(IndexExp e)
|
void visitIndex(IndexExp e)
|
||||||
{
|
{
|
||||||
Type tb = e.e1.type.toBasetype();
|
Type tb = e.e1.type.toBasetype();
|
||||||
if (auto ve = e.e1.isVarExp())
|
|
||||||
{
|
|
||||||
VarDeclaration v = ve.var.isVarDeclaration();
|
|
||||||
if (v && v.isTypesafeVariadicArray)
|
|
||||||
{
|
|
||||||
er.byRef(v, retRefTransition);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tb.ty == Tsarray)
|
if (tb.ty == Tsarray)
|
||||||
{
|
{
|
||||||
escapeByRef(e.e1, er, retRefTransition);
|
escapeByRef(e.e1, er, retRefTransition);
|
||||||
|
|
|
@ -323,9 +323,9 @@ int[] testSlice2() { int[3] sa; int n; return sa[n..2][1..2]; }
|
||||||
/*
|
/*
|
||||||
TEST_OUTPUT:
|
TEST_OUTPUT:
|
||||||
---
|
---
|
||||||
fail_compilation/fail13902.d(324): Error: returning `vda[0]` escapes a reference to parameter `vda`
|
fail_compilation/fail13902.d(324): Error: returning `vda[0]` escapes a reference to variadic parameter `vda`
|
||||||
|
fail_compilation/fail13902.d(325): Error: returning `vda[]` escapes a reference to variadic parameter `vda`
|
||||||
---
|
---
|
||||||
|
|
||||||
*/
|
*/
|
||||||
ref int testDynamicArrayVariadic1(int[] vda...) { return vda[0]; }
|
ref int testDynamicArrayVariadic1(int[] vda...) { return vda[0]; }
|
||||||
@safe int[] testDynamicArrayVariadic2(int[] vda...) { return vda[]; }
|
@safe int[] testDynamicArrayVariadic2(int[] vda...) { return vda[]; }
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
REQUIRED_ARGS: -preview=dip1000
|
REQUIRED_ARGS: -preview=dip1000
|
||||||
TEST_OUTPUT:
|
TEST_OUTPUT:
|
||||||
---
|
---
|
||||||
fail_compilation/test23022.d(14): Error: scope parameter `p` may not be returned
|
fail_compilation/test23022.d(14): Error: returning `p` escapes a reference to variadic parameter `p`
|
||||||
---
|
---
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue