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

Formatting a call on an instance variable directly within short block syntax #15112

Open
Blacksmoke16 opened this issue Oct 21, 2024 · 0 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter

Comments

@Blacksmoke16
Copy link
Member

Blacksmoke16 commented Oct 21, 2024

There seems to be some oddities around trying to format a line that is doing a call on an instance variable directly within the short block syntax. For example:

SomeType.some_block?(&.obj.@internal.call(1))
puts "done"

Results in:

$ crystal tool format --show-backtrace test.cr
expecting DELIMITER_START, not `IDENT, puts`, at :2:1 (Exception)
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'raise<Exception>:NoReturn'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'raise<String>:NoReturn'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'Crystal::Formatter#visit<Crystal::StringLiteral>:Bool'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::Formatter>:(Bool | Nil)'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'Crystal::Formatter#format_args_simple<Array(Crystal::ASTNode+), Int32, Bool>:Tuple(Bool, Bool, Int32)'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'Crystal::Formatter#format_args<Array(Crystal::ASTNode+), Bool, (Array(Crystal::NamedArgument) | Nil), (Crystal::ASTNode+ | Nil), Int32, Bool>:Tuple(Bool | Nil, Bool, Int32)'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'Crystal::Formatter#format_call_args<Crystal::Call, Bool, Int32>:Tuple(Bool | Nil, Bool, Int32)'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'Crystal::Formatter#visit<Crystal::Call>:Bool'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::Formatter>:(Bool | Nil)'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'Crystal::Formatter#visit<Crystal::Expressions>:Bool'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::Formatter>:(Bool | Nil)'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'Crystal::Command::FormatCommand#format_source<String, String>:(IO+ | Int32 | Nil)'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'Crystal::Command::FormatCommand#format_many<Array(String)>:Nil'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'Crystal::Command#format:NoReturn'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'Crystal::Command#tool:(Bool | Nil)'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'Crystal::Command::run<Array(String)>:(Bool | Crystal::Repl::Value | Nil)'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in '__crystal_main'
  from /opt/homebrew/Cellar/crystal/1.14.0_1/bin/crystal in 'main'

However, if you remove the puts "done" line, it doesn't error, but gets formatted to:

SomeType.some_block?(&.__arg0.obj.@internal call 1)

Which isn't really correct at all.

@Blacksmoke16 Blacksmoke16 added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter labels Oct 21, 2024
ysbaddaden added a commit to ysbaddaden/crystal that referenced this issue Nov 4, 2024
ysbaddaden added a commit to ysbaddaden/crystal that referenced this issue Nov 4, 2024
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

No branches or pull requests

1 participant