Bug 13526 – Allow to declare a variable in with statement: with(auto p = new Panel())

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-09-24T14:37:39Z
Last change time
2024-12-13T18:29:22Z
Assigned to
No Owner
Creator
Andre
See also
https://issues.dlang.org/show_bug.cgi?id=11070, https://issues.dlang.org/show_bug.cgi?id=16140
Moved to GitHub: dmd#18890 →

Attachments

IDFilenameSummaryContent-TypeSize
1432with_allows_vardecls.patchpreliminary realizationtext/plain8797
1433test00.dsimple testcasetext/plain666
1437with_allows_vardecls.patchnew version; this one requires 'parser code cleanup' from 11070text/plain4504

Comments

Comment #0 by andre — 2014-09-24T14:37:39Z
Currently this code is not accepted: with (auto p = new Panel()) { parent = this; text = "bla"; with (new Button()) { parent = p; // Here p is needed text = "bla2"; } } auto is not allowed in with statement. p is needed as parent attribute of the new button. One workaround would be to change the coding to: Panel p; with (p = new Panel()) {...} While this coding is working, it seems like a missing feature auto is not working. Could you check? In the discussion http://forum.dlang.org/thread/[email protected] also someone mentioned auto would make sense in switch, but can't judge on that.
Comment #1 by ketmar — 2014-09-24T23:40:08Z
Created attachment 1432 preliminary realization this is quick-and-dirty patch that allows declarations in with(). hdrgen emits fixed .di files too. please note that this is my first patch outside of parser scope and i'm not sure what i'm doing here. it seems to work on simple test cases (see second attachement) but it need to be reviewed by someone who knows compiler internals. so far the patch seems to not breaking existing code, so it can be safely tested.
Comment #2 by ketmar — 2014-09-24T23:40:52Z
Created attachment 1433 simple testcase
Comment #3 by ketmar — 2014-09-27T01:38:35Z
Created attachment 1437 new version; this one requires 'parser code cleanup' from 11070
Comment #4 by ketmar — 2015-03-22T02:49:53Z
*** Issue 14316 has been marked as a duplicate of this issue. ***
Comment #5 by ketmar — 2016-06-09T07:01:02Z
*** Issue 16140 has been marked as a duplicate of this issue. ***
Comment #6 by robert.schadek — 2024-12-13T18:29:22Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18890 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB