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 crash when heredoc contains string interpolations and do-end block #9473

Closed
shootingfly opened this issue Jun 13, 2020 · 2 comments · Fixed by #9475
Closed

Formatter crash when heredoc contains string interpolations and do-end block #9473

shootingfly opened this issue Jun 13, 2020 · 2 comments · Fixed by #9475
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter

Comments

@shootingfly
Copy link

Error was happened when I formatted a heredoc that contains do-end block and Interpolation.
It works if there are not interpolations in do-end block.

crystal tool format --show-backtrace /home/rocky/Workspace/Crystal/jbuilder/src/jbuilder/embedder.cr

embedder.cr

puts <<-Crystal
  Jbuilder.new do |json|
    #{File.read(ARGV[0])}
  end.to_json
Crystal

Backtrace

expecting DELIMITER_START, not `CONST, File`, at :3:7 (Exception)
  from ../../../../../crystal/src/io/memory.cr:433:13 in 'visit'
  from ../../../../../crystal/src/compiler/crystal/tools/formatter.cr:160:9 in 'visit_string_interpolation'
  from ../../../../../crystal/src/compiler/crystal/tools/formatter.cr:648:13 in 'next_token'
  from ../../../../../crystal/src/slice.cr:229:5 in 'accept'
  from ../../../../../crystal/src/compiler/crystal/syntax/visitor.cr:20:7 in 'format_args_simple'
  from ../../../../../crystal/src/compiler/crystal/tools/formatter.cr:2719:54 in 'format_args'
  from ../../../../../crystal/src/compiler/crystal/tools/formatter.cr:2713:5 in 'visit'
  from ../../../../../crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from ../../../../../crystal/src/compiler/crystal/tools/formatter.cr:17:7 in 'format_source'
  from ../../../../../crystal/src/compiler/crystal/command/format.cr:103:9 in 'format_many'
  from ../../../../../crystal/src/compiler/crystal/command/format.cr:53:5 in 'format'
  from ../../../../../crystal/src/hash.cr:896:11 in 'tool'
  from ../../../../../crystal/src/compiler/crystal/command.cr:107:7 in 'run'
  from ../../../../../crystal/src/compiler/crystal.cr:11:1 in '__crystal_main'
  from ../../../../../crystal/src/crystal/main.cr:105:5 in 'main'
  from src/env/__libc_start_main.c:94:2 in 'libc_start_main_stage2'

couldn't format '/home/rocky/Workspace/Crystal/jbuilder/src/jbuilder/embedder.cr', please report a bug including the contents of it: https://github.com/crystal-lang/crystal/issues

Crystal Version

Crystal 0.35.0 [3c48f311f] (2020-06-09)

LLVM: 8.0.0
Default target: x86_64-unknown-linux-gnu

System

Linux rocky-PC 4.15.0-29deepin-generic #31 SMP Fri Jul 27 07:12:08 UTC 2018 x86_64 GNU/Linux
@jhass
Copy link
Member

jhass commented Jun 13, 2020

Mmh, #9362 redux? /cc @makenowjust :)

@jhass jhass added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:tools:formatter labels Jun 13, 2020
@makenowjust
Copy link
Contributor

do ... end is not important. We can reproduce it on the following:

puts <<-FOO
foo
#{1}
FOO

The second (or more) line interpolation inside no indent heredoc causes this bug.

makenowjust added a commit to makenowjust/crystal that referenced this issue Jun 13, 2020
Fixed crystal-lang#9473

It is important to simplify the formatter implementation.
paulcsmith added a commit to luckyframework/lucky that referenced this issue Jun 16, 2020
paulcsmith added a commit to luckyframework/lucky that referenced this issue Jun 16, 2020
* Use Socket::Address instead of String for Request#remove_address

* Use Process#signal

* Fix specs due to Log::Severity::Warn rename

* Use ::Log::Metadata

* Fixes due to Log::Severity::Warn rename

* Use Log::Entry#data as local_context

* Use compress/gzip

* Use Log::Entry#data as local_context

* Socket::Address

* Refactor due to Log::Metadata / Log::Metadata::Value split

* Update shards

* Use latest Dexter

* Use Crystal 0.35.0

* Remove unused Habitat setting

* Use more specific rescue clause

Using a generic rescue can hide other legitimate errors. Let's use a
more specific one to catch just the socket error

* Reformat helpful_error to avoid bug in Crystal

crystal-lang/crystal#9473

Co-authored-by: Brian J. Cardiff <[email protected]>
paulcsmith added a commit to luckyframework/lucky that referenced this issue Jun 16, 2020
* Use Socket::Address instead of String for Request#remove_address

* Use Process#signal

* Fix specs due to Log::Severity::Warn rename

* Use ::Log::Metadata

* Fixes due to Log::Severity::Warn rename

* Use Log::Entry#data as local_context

* Use compress/gzip

* Use Log::Entry#data as local_context

* Socket::Address

* Refactor due to Log::Metadata / Log::Metadata::Value split

* Update shards

* Use latest Dexter

* Use Crystal 0.35.0

* Remove unused Habitat setting

* Use more specific rescue clause

Using a generic rescue can hide other legitimate errors. Let's use a
more specific one to catch just the socket error

* Reformat helpful_error to avoid bug in Crystal

crystal-lang/crystal#9473

Co-authored-by: Brian J. Cardiff <[email protected]>
asterite pushed a commit that referenced this issue Sep 5, 2020
…#9475)

Fixed #9473

It is important to simplify the formatter implementation.
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.

3 participants