Fix Issue 23912 - Destructor disables scope inference

This commit is contained in:
RazvanN7 2023-05-16 13:07:01 +03:00 committed by The Dlang Bot
parent 085980206a
commit c67bb5945b
2 changed files with 31 additions and 0 deletions

View file

@ -699,6 +699,20 @@ VarDeclaration expToVariable(Expression e)
case EXP.super_:
return (cast(ThisExp)e).var.isVarDeclaration();
// Temporaries for rvalues that need destruction
// are of form: (T s = rvalue, s). For these cases
// we can just return var declaration of `s`. However,
// this is intentionally not calling `Expression.extractLast`
// because at this point we cannot infer the var declaration
// of more complex generated comma expressions such as the
// one for the array append hook.
case EXP.comma:
{
if (auto ve = e.isCommaExp().e2.isVarExp())
return ve.var.isVarDeclaration();
return null;
}
default:
return null;
}

View file

@ -0,0 +1,17 @@
// https://issues.dlang.org/show_bug.cgi?id=23912
// REQUIRED_ARGS: -preview=dip1000
struct Test
{
string val;
this(return scope string val) scope @safe {}
~this() scope @safe {}
}
void giver(scope string input) @safe
{
accepts(Test(input));
}
void accepts(scope Test test) @safe {}