Skip to content

Hash literal without braces has invalid syntax after formatting #308

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

Closed
naveg opened this issue Feb 9, 2023 · 1 comment · Fixed by #319
Closed

Hash literal without braces has invalid syntax after formatting #308

naveg opened this issue Feb 9, 2023 · 1 comment · Fixed by #319

Comments

@naveg
Copy link

naveg commented Feb 9, 2023

This code:

def a
  return :foo => "bar"
end

is valid Ruby:

irb(main):001:1* def a
irb(main):002:1*   return :foo => "bar"
irb(main):003:0> end
=> :a
irb(main):004:0> a
=> {:foo=>"bar"}
irb(main):005:0> a.class
=> Hash

Syntax tree formats this code to:

def a
  return foo: "bar"
end

which is not:

irb(main):001:1* def a
irb(main):002:1>   return foo: "bar"
irb(main):003:0> end
/Users/Evan.Goldenberg/.asdf/installs/ruby/3.2.0/lib/ruby/3.2.0/irb/workspace.rb:119:in `eval': (irb):2: syntax error, unexpected ':', expecting `end' or dummy end (SyntaxError)
  return foo: "bar"
            ^

	from /Users/Evan.Goldenberg/.asdf/installs/ruby/3.2.0/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
	from /Users/Evan.Goldenberg/.asdf/installs/ruby/3.2.0/bin/irb:25:in `load'
	from /Users/Evan.Goldenberg/.asdf/installs/ruby/3.2.0/bin/irb:25:in `<main>'
@kddnewton
Copy link
Member

Ahh that's annoying. I'll get it fixed, thanks for reporting!

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

Successfully merging a pull request may close this issue.

2 participants