boo-lang / boo

The Boo Programming Language.
BSD 3-Clause "New" or "Revised" License
858 stars 146 forks source link

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

Open dnewhall opened 7 years ago

dnewhall commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

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