crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.37k stars 1.62k forks source link

formatter cause syntax error. #14609

Open zw963 opened 4 months ago

zw963 commented 4 months ago

Bug Report

Following is a valid crystal script.

foo.cr

    foo do
      bar(
        script: "on change put my.value1 into the previous <span/>",
#         script: "
# on change set (previous <input/>).value and (previous <span/>).innerHTML to my.value1
# "
      ) do
      end
    end

But, after format, get following invalid expression.

 ╰─ $ cat foo.cr |crystal tool format -
foo do
  bar(
    script: "on change put my.value1 into the previous <span/>" #         script: "
  # on change set (previous <input/>).value and (previous <span/>).innerHTML to my.value1
  # "
,
  ) do
  end
end
In foo.cr:6:1

 6 | ,
     ^
Error: expecting token ')', not ','

Thanks

zw963 commented 4 months ago

Can be reduced:

Before

foo do
      bar(
        arg1: "",
        # arg2: ""
      ) do
      end
    end

After

foo do
  bar(
    arg1: "" # arg2: ""
,
  ) do
  end
end
straight-shoota commented 4 months ago

This looks like two bug: The formatter should not butcher full-line comments in an argument list. But the parser should also be able to read the resulting code. There's nothing wrong with it.

So keeping this issue focussed on the formatter, I created #14616 for the parser bug.