diff --git a/compiler/src/dmd/expression.d b/compiler/src/dmd/expression.d index c034cbb0ef..a441a55468 100644 --- a/compiler/src/dmd/expression.d +++ b/compiler/src/dmd/expression.d @@ -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; } diff --git a/compiler/test/compilable/test23912.d b/compiler/test/compilable/test23912.d new file mode 100644 index 0000000000..d89d3026e8 --- /dev/null +++ b/compiler/test/compilable/test23912.d @@ -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 {}