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

Syntax error when parsing 1.9 syntax for lambda with empty parentheses #2704

Closed
gregspurrier opened this issue Mar 15, 2015 · 1 comment
Closed

Comments

@gregspurrier
Copy link

If the argument list for a lambda expression using Ruby 1.9's arrow syntax is a set of empty parentheses, JRuby throws a syntax error:

irb(main):001:0> RUBY_ENGINE
=> "jruby"
irb(main):002:0> JRUBY_VERSION
=> "1.7.19"
irb(main):003:0> -> () {}
SyntaxError: (irb):3: syntax error, unexpected tLPAREN_ARG
-> () {}
   ^
        from org/jruby/RubyKernel.java:1107:in `eval'
        from org/jruby/RubyKernel.java:1507:in `loop'
        from org/jruby/RubyKernel.java:1270:in `catch'
        from org/jruby/RubyKernel.java:1270:in `catch'
        from /home/greg/.rbenv/versions/jruby-1.7.19/bin/irb:13:in `(root)'

Contrast this with MRI, which accepts this syntax:

irb(main):001:0> RUBY_ENGINE
=> "ruby"
irb(main):002:0> RUBY_VERSION
=> "2.2.1"
irb(main):003:0> -> () {}
=> #<Proc:0x007f03f6ab8988@(irb):3 (lambda)>
@enebo enebo added this to the Invalid or Duplicate milestone Mar 16, 2015
@enebo
Copy link
Member

enebo commented Mar 16, 2015

This was apparently a change in grammar introduced in Ruby 2.0 and Ruby 1.9.3 seems to behave the same way for me:

mri19 -ve '-> () {}'
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-darwin13.4.0]
-e:1: syntax error, unexpected tLPAREN_ARG, expecting keyword_do_LAMBDA or tLAMBEG
-> () {}
    ^

This is working ok in JRuby 9k (which is 2.2.1) so I am resolving this.

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

2 participants