mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
Fix Issue 23912 - Destructor disables scope inference
This commit is contained in:
parent
085980206a
commit
c67bb5945b
2 changed files with 31 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
17
compiler/test/compilable/test23912.d
Normal file
17
compiler/test/compilable/test23912.d
Normal 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 {}
|
Loading…
Add table
Add a link
Reference in a new issue