Bug 17265 – WithStatement: Find better Example for what "with" really does

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
Other
OS
Other
Creation time
2017-03-17T20:10:14Z
Last change time
2017-12-18T22:56:17Z
Keywords
pull
Assigned to
No Owner
Creator
Stefan

Attachments

IDFilenameSummaryContent-TypeSize
1643withstatement2.dtestcasetext/plain565

Comments

Comment #0 by kdevel — 2017-03-17T20:10:14Z
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.
Comment #1 by kdevel — 2017-03-17T20:12:54Z
Created attachment 1643 testcase
Comment #2 by greensunny12 — 2017-06-15T04:06:29Z
Comment #3 by github-bugzilla — 2017-12-10T14:53:34Z
Commits pushed to master at https://github.com/dlang/dlang.org https://github.com/dlang/dlang.org/commit/472ddd30a416c7263d3cdf45436e484c97a15573 Fix Issue 17265 - WithStatement: Use better Example https://github.com/dlang/dlang.org/commit/19db8d0730f4e17e3594500c3ee143769ffdc901 Merge pull request #1699 from wilzbach/fix-17265 Fix Issue 17265 - WithStatement: Find better Example for what with really does merged-on-behalf-of: Petar Kirov <[email protected]>
Comment #4 by kdevel — 2017-12-10T15:53:51Z
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