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

Cannot pass hash directly to a method without parentheses #7923

Closed
Blacksmoke16 opened this issue Jun 25, 2019 · 4 comments
Closed

Cannot pass hash directly to a method without parentheses #7923

Blacksmoke16 opened this issue Jun 25, 2019 · 4 comments

Comments

@Blacksmoke16
Copy link
Member

Blacksmoke16 commented Jun 25, 2019

def do_work(hash : Hash(String, String)); end

do_work {"foo" => "bar"}

Syntax error in eval:3: unexpected token: =>

Assigning the hash to a variable first or adding parentheses to the method invocation works.

@Blacksmoke16 Blacksmoke16 changed the title Cannot pass hash directly to a method Cannot pass hash directly to a method without parentheses Jun 25, 2019
@j8r
Copy link
Contributor

j8r commented Jun 25, 2019

I guess that's because parentheses are also used for blocks.

@jhass
Copy link
Member

jhass commented Jun 25, 2019

Yes, this a limitation in the grammar.

@jhass jhass closed this as completed Jun 25, 2019
@oprypin
Copy link
Member

oprypin commented Jun 25, 2019

To expand on why this is unsolvable, otherwise the compiler will need to special-case this with 3-level deep lookahead. Which is usually seen as a very bad thing (sorry for not expanding on that one).

do_work { could be both
do_work {"foo" could be both
do_work {"foo" = could be both
do_work {"foo" => ok right, now I can go back and actually parse this as Hash

@asterite
Copy link
Member

Duplicate of #6224, #2746, #4826, #1051

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

5 participants