syntax_suggest icon indicating copy to clipboard operation
syntax_suggest copied to clipboard

Accidental if instead of a block

Open schneems opened this issue 2 years ago • 0 comments

I don't know if we can improve this but I hit this syntax error today when writing rspec:

Unmatched keyword, missing `end' ?
  2  describe "something" do
> 3    if "does something" do
> 5    end
  6  end
/tmp/scratchrb:3: syntax error, unexpected `do', expecting `then' or ';' or '\n' (SyntaxError)
  if "does something" do
                      ^~

(I used if instead of it).

Both if and do need an end. I think we could explain this better. In this case the original error says "unexpected do', expecting then' or ';' or '\n'". Perhaps as we're trying to explain the problem we should verify that the syntax error of our captured block matches the syntax error of the document, do something differently.

Generated by this code:

describe "something" do
  if "does something" do
    print "foo"
  end
end

schneems avatar Sep 28 '23 17:09 schneems