-
Notifications
You must be signed in to change notification settings - Fork 2k
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
String after implicit object #618
Comments
Perhaps it would be a good idea if compact literal expansions (like |
Actually, while this is baffling behavior at first glance, I think it's OK. Consider that in Ruby, implicit hashes are allowed only for the last argument precisely because humans would have a hard time seeing that
So, if you use a hash as an earlier argument, you need to use curly braces. It seems wise to me, as a stylistic matter, to use curly braces for a hash that isn't the last argument to a function. Given the stylistic convention, scenarios like the above would be unlikely for two reasons: First, the caller would use curly braces around the hash; and second, the person who wrote the function would have made the hash the second argument rather than the first. Also consider syntax highlighting. If So, I don't strenuously object to sethaurus' proposal, but I don't think it's necessary, either. |
TrevorBurnham: That makes sense. Thank you. |
Thanks for reporting this ... it's not too hard of a fix -- just one more check to make, while searching for the end of the implicit object. Here's the patch: http://github.com/jashkenas/coffee-script/commit/474c372b17cd6ebd5eb6c26ef7f6cb5769c881bf Closing the ticket. |
Cool. Thank you, jashkenas! |
Sorry, devtime, had to revert this commit for the following reason: http://github.com/jashkenas/coffee-script/issues/#issue/631 |
Ok, jashkenas. No biggie. Thanks for letting me know. |
To prevent this, how about making object shorthand syntax a little more explicit: |
satyr: I like it! jashkenas: will you consider reopening this issue? or should we create a new one for satyr's proposal? Thanks. |
I like it as well. Nice suggestion. |
I like the way it is now. TrevorBurnham's comment on how ruby does it, also applying for pythons **kwargs, is tried and true, and makes perfect sense. To solve it, you can already be expicit: |
I like satyr's proposal. How often would you really want to do On a side note, why is |
StanAngeloff: I agree with you -- it's much more common for me to need a string after a hash than needing a "string key with the same string value". |
Also, the current behavior is counterintuitive. Most developers who'll come by the sort of code above for the first time will think that the second parameter is a string. |
If it can be done, wtihout requring explicit brackets great. |
I spent a long time trying to solve this last night, and got mostly nowhere. If anyone has some brilliant ideas for parsing it, I'd love to hear them. This is the crux of the issue.
In a perfect world would compile into (I think):
The trick is that when we're rewriting the token stream and inserting implicit parentheses and braces, the braces go first. I can't think of a rule that would correctly distinguish the two parses above, and would know that the implicit braces are supposed to end early for the first bit of code. Something where the brace and paren rules mutually invoke each other might do the trick... |
It can get a bit harder: multiple inline objects. Like: |
I haven't found a way to make this case parsable, in general. I'm afraid we'll have to accept it as a known limitation of implicit objects (which, for the record, are still more flexible than in Ruby, for example). Closing this ticket as |
A patch to fix this issue is now on master, which now compiles the original test case for this issue correctly. If you have a minute to give master a try, and see if it's working for your use cases, please do. |
jashkenas, Wow! This is good news! I'll be trying this out later today. I'm afraid I haven't been keeping up with the commits lately -- Is the current code on master as stable (or more) as 1.0 by now? Would you say it's pretty safe to start compiling my code with it? Or should I be using some branch? |
|
Sure. Will do. :) |
Some observations:
|
yep the fix is just a hack to prevent unexpected results. |
Those are serious failures, though. Is the hack more generalizable? |
Looks like the discussion is happening on #1061 ... let's keep it over there. |
Shouldn't this:
get compiled into:
instead of:
??
The text was updated successfully, but these errors were encountered: