Skip to content

Commit 6027a94

Browse files
makenowjustRX14
authored andcommittedNov 19, 2017
Format: fix to format $1? (#5313)
Fixed #5310
1 parent 818c438 commit 6027a94

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed
 

Diff for: ‎spec/compiler/formatter/formatter_spec.cr

+1
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ describe Crystal::Formatter do
414414
assert_format "$1.bar", "$1.bar"
415415
assert_format "$0", "$0"
416416
assert_format "$0.bar", "$0.bar"
417+
assert_format "$1?"
417418

418419
assert_format "foo . is_a? ( Bar )", "foo.is_a?(Bar)"
419420
assert_format "foo . responds_to?( :bar )", "foo.responds_to?(:bar)"

Diff for: ‎src/compiler/crystal/tools/formatter.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,7 @@ module Crystal
20612061
column = @column
20622062

20632063
# Special case: $1, $2, ...
2064-
if @token.type == :GLOBAL_MATCH_DATA_INDEX && node.name == "[]" && obj.is_a?(Global)
2064+
if @token.type == :GLOBAL_MATCH_DATA_INDEX && (node.name == "[]" || node.name == "[]?") && obj.is_a?(Global)
20652065
write "$"
20662066
write @token.value
20672067
next_token

0 commit comments

Comments
 (0)
Please sign in to comment.