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

Macros fail to parse literal select statement #9620

Closed
z64 opened this issue Jul 18, 2020 · 1 comment · Fixed by #9624
Closed

Macros fail to parse literal select statement #9620

z64 opened this issue Jul 18, 2020 · 1 comment · Fixed by #9624
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:parser

Comments

@z64
Copy link
Contributor

z64 commented Jul 18, 2020

The following fails to parse:

macro test(c1, c2)
  select 
  when {{c1}}.receive
    # ..
  when {{c2}}.receive
    # ..
  end
end

With the error:

In test.cr:8:1

 8 | end
     ^
Error: expecting token 'EOF', not 'end'

The workaround is to do something like the following:

macro test(c1, c2)
  {{"select".id}}
  when {{c1}}.receive
    # ..
  when {{c2}}.receive
    # ..
  {{"end".id}}
end

Which will emit the correct code.


Crystal 0.35.1 (2020-06-21)

LLVM: 10.0.0
Default target: x86_64-pc-linux-gnu

@Blacksmoke16
Copy link
Member

Try wrapping it in {% begin %} ... {% end %}. I.e.

macro test(c1, c2)
  {% begin %}
    select 
    when {{c1}}.receive
      # ..
    when {{c2}}.receive
      # ..
    end
  {% end %}
end

@jhass jhass added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:parser labels Jul 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants