Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to declare a variable in with statement: with(auto p = new Panel()) #18890

Open
dlangBugzillaToGithub opened this issue Sep 24, 2014 · 5 comments

Comments

@dlangBugzillaToGithub
Copy link

Andre reported this on 2014-09-24T14:37:39Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=13526

CC List

Description

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/alaqjnmfckedhuvypvps@forum.dlang.org
also someone mentioned auto would make sense in switch,
but can't judge on that.

!!!There are attachements in the bugzilla issue that have not been copied over!!!

@dlangBugzillaToGithub
Copy link
Author

ketmar commented on 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.

@dlangBugzillaToGithub
Copy link
Author

ketmar commented on 2014-09-24T23:40:52Z

Created attachment 1433
simple testcase

@dlangBugzillaToGithub
Copy link
Author

ketmar commented on 2014-09-27T01:38:35Z

Created attachment 1437
new version; this one requires 'parser code cleanup' from 11070

@dlangBugzillaToGithub
Copy link
Author

ketmar commented on 2015-03-22T02:49:53Z

*** Issue 14316 has been marked as a duplicate of this issue. ***

@dlangBugzillaToGithub
Copy link
Author

ketmar commented on 2016-06-09T07:01:02Z

*** Issue 16140 has been marked as a duplicate of this issue. ***

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant