Skip to content

Commit

Permalink
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
@@ -391,6 +391,8 @@ describe Crystal::Formatter do
assert_format "$? = 1", "$? = 1"
assert_format "$1", "$1"
assert_format "$1.bar", "$1.bar"
assert_format "$0", "$0"
assert_format "$0.bar", "$0.bar"

assert_format "foo . is_a? ( Bar )", "foo.is_a?(Bar)"
assert_format "foo . responds_to?( :bar )", "foo.responds_to?(:bar)"
8 changes: 8 additions & 0 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
@@ -889,6 +889,14 @@ module Crystal
end

def visit(node : Path)
# This is the case of $0, which generates `PROGRAM_NAME` by the parser
if @token.type == :GLOBAL_MATCH_DATA_INDEX
write "$"
write @token.value
next_token
return false
end

check_open_paren

# Sometimes the :: is not present because the parser generates ::Nil, for example

0 comments on commit d30f29c

Please sign in to comment.