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

inline variable in switch #1119

Closed
gavinking opened this issue Oct 26, 2014 · 6 comments
Closed

inline variable in switch #1119

gavinking opened this issue Oct 26, 2014 · 6 comments

Comments

@gavinking
Copy link
Member

Previously, I had been avoiding adding support for the rather convenient form switch (val=expression()) because it is in principle ambiguous: val=expression() is a legal expression. However, I just noticed that we let the syntax try (resource=expression()) slip into the language, which features the same in-principle ambiguity.

I don't think either of these is truly ambiguous in any meaningful sense: the semantic distance between an assignment and an inline variable specification is not very large, and I anyway don't think anyone writes assignments in switch or try.

So I'm inclined to allow this syntax in both switch and try. If anyone disagrees with my analysis, then we should disallow the syntax in both places.

@gavinking
Copy link
Member Author

Initial implementation of this is in branch 1119. Requires support in the backends, obviously.

Also still requires updates to the spec and tests.

@lucaswerkmeister
Copy link
Member

I anyway don't think anyone writes assignments in switch or try.

I did it here… but it won’t hurt much if the switch introduces a new variable instead of assigning to an existing variable.

@gavinking
Copy link
Member Author

but it won’t hurt much if the switch introduces a new variable instead of assigning to an existing variable

:-(

Whenever I think "surely no-one has ever done this", it always turns out that someone has done it, and I break their code.

@lucaswerkmeister
Copy link
Member

Eh, the code isn’t even a week old, you don’t have to feel bad about breaking that :D

And I agree that very few people are likely to have done that.

gavinking added a commit that referenced this issue Nov 14, 2014
gavinking added a commit that referenced this issue Nov 17, 2014
lucaswerkmeister added a commit to eclipse-archived/ceylon.formatter that referenced this issue Nov 19, 2014
We can now declare inline variables in switch.
lucaswerkmeister added a commit to eclipse-archived/ceylon.formatter that referenced this issue Nov 19, 2014
lucaswerkmeister added a commit to eclipse-archived/ceylon.formatter that referenced this issue Nov 19, 2014
Update for ceylon/ceylon-spec#1119: Inline variable in switch.
@gavinking
Copy link
Member Author

This still needs a spec. I'm on it!

@gavinking
Copy link
Member Author

Spec is done. Closing!

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

2 participants