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

Feature request: Allow type declarations (f as Foo) in using block expression. #159

Open
dnewhall opened this issue Jan 28, 2017 · 3 comments

Comments

@dnewhall
Copy link

It would be very useful to be able to write this:

using f as Foo = AcquireAndReturnSubtypeOfFoo():
f.DoFooStuff()

This is currently not allowed by the compiler (the "as Foo" part) but similar constructions are allowed in C# and Visual Basic and it would be nice to have this behavior.

@masonwheeler
Copy link
Contributor

Unfortunately, there's no good way to support this.

using is a macro, and macros can have expressions as arguments, and a Block as the body. But variable as type = SomeValue is a DeclarationStatement, which is a Statement rather than an Expression, and trying to change that would require changing the parser and the AST and potentially breaking a lot of things.

@popcatalin81
Copy link

Maybe one way to achieve this more easily is with the experimental 'var' macro. using var f = Acq... this way 'f = Acq' is an expression while the inner var macro can add the declaration statement to the AST.

@masonwheeler
Copy link
Contributor

@popcatalin81 That still won't parse, because macros are Statements, not Expressions.

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

No branches or pull requests

3 participants