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

Formatter fails with line continuation character before comment #12202

Closed
ThatsJustCheesy opened this issue Jul 5, 2022 · 0 comments · Fixed by #12319
Closed

Formatter fails with line continuation character before comment #12202

ThatsJustCheesy opened this issue Jul 5, 2022 · 0 comments · Fixed by #12319
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter

Comments

@ThatsJustCheesy
Copy link

ThatsJustCheesy commented Jul 5, 2022

Hello again! I've run into a formatter issue.

This:

bug = \
  # blah
  nil

and this:

bug = \
  # blah
  puts(["hi"])

both trigger a crash in the formatter.

Output from first snippet
> crystal tool format --show-backtrace
expecting keyword nil, not `COMMENT, # blah`, at :2:3 (Exception)
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'raise:NoReturn'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'raise:NoReturn'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::Formatter#write_keyword:Crystal::Token'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept:(Bool | Nil)'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::Formatter#accept_assign_value:(Array(Crystal::Formatter::AlignInfo) | Nil)'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept:(Bool | Nil)'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::Command::FormatCommand#format_source:(IO+ | Int32 | Nil)'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::Command::FormatCommand#format_many:Nil'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::Command#format:NoReturn'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::Command#tool:(Bool | Nil)'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in '__crystal_main'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'main'

couldn't format <snipped-filename>, please report a bug including the contents of it: https://github.com/crystal-lang/crystal/issues

Output from second snippet
> crystal tool format --show-backtrace
Nil assertion failed (NilAssertionError)
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'raise:NoReturn'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Nil#not_nil!:NoReturn'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept:(Bool | Nil)'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::Formatter#format_args_simple:Tuple(Bool, Bool, Int32)'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::Formatter#format_args:Tuple(Bool | Nil, Bool, Int32)'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::Formatter#visit:Bool'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept:(Bool | Nil)'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::Formatter#accept_assign_value:(Array(Crystal::Formatter::AlignInfo) | Nil)'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept:(Bool | Nil)'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::Command::FormatCommand#format_source:(IO+ | Int32 | Nil)'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::Command::FormatCommand#format_many:Nil'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::Command#format:NoReturn'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'Crystal::Command#tool:(Bool | Nil)'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in '__crystal_main'
  from /opt/homebrew/Cellar/crystal/1.4.1/libexec/crystal in 'main'

couldn't format <snipped-filename> please report a bug including the contents of it: https://github.com/crystal-lang/crystal/issues

I added the \ to try to suppress the formatter's default behavior of moving the comment up onto line 1, leaving line 2 blank:

bug = # blah

  puts(["hi"])

Compiler version:

> crystal --version
Crystal 1.4.1 (2022-04-22)

LLVM: 13.0.1
Default target: aarch64-apple-darwin21.5.0

Quick tangentially related question: Is automatic splitting of long lines on the roadmap? It would make the formatter much more useful to me.

Thanks :)

@ThatsJustCheesy ThatsJustCheesy added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label Jul 5, 2022
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:tools:formatter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants