The documentation
http://dlang.org/spec/statement.html#WithStatement
claims an equivalence of
with (expression)
{
...
ident;
}
and
{
Object tmp;
tmp = expression;
...
tmp.ident;
}
This does not hold if "Object" refers to a struct type. While the former invokes ident on the original object (struct), the latter invokes it on a copy. Hence there is no equivalence.
The false assertion
"with (expression)
{
...
ident;
}
is semantically equivalent to:
{
Object tmp;
tmp = expression;
...
tmp.ident;
}"
is still on <https://dlang.org/spec/statement.html#WithStatement>. Please compile and run the testcase withstatement2.d. If the assertion were true, the program would be expected to print
before
after
before
after
But it really prints
before
after
before
before
Comment #5 by kdevel — 2017-12-10T16:09:32Z
Proposal:
"with (expression)
{
...
ident;
}
is semantically equivalent to:
{
auto ptr = &expression;
...
ptr.ident;
}"
Comment #6 by greeenify — 2017-12-10T18:11:39Z
See the PR. This has been rejected.
Comment #7 by github-bugzilla — 2017-12-18T22:55:15Z