Skip to content

Commit 8a1129d

Browse files
authored
Do not open nesting for character literals (#1190)
* Do not open nesting for character literals To fix the indentation of `end` in the following code: ```ruby if c == ?a puts "a" end ``` * Check node.opening for prism-latest To fix the test failures at https://github.com/ruby/irb/actions/runs/23577491147/job/68670877251?pr=1190
1 parent 24007f9 commit 8a1129d

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

lib/irb/nesting_parser.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def heredoc_string_like(node, type)
222222
# Heredoc closing contains trailing newline. We need to exclude it
223223
close_location_start(node.closing_loc) if node.closing_loc && !node.closing.empty?
224224
elsif node.opening
225+
return if node.opening == '?' && node.closing.nil? # Character literal has no closing
225226
open_location(node.location, type, node.opening)
226227
if node.closing && node.closing != ''
227228
# Closing of `"#{\n` is "\n". We need to treat it as not-closed.

test/irb/test_nesting_parser.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,5 +347,15 @@ def test_case_in
347347
assert_equal(['in'], next_opens.map(&:tok))
348348
end
349349
end
350+
351+
def test_char_literal
352+
code = <<~EOS
353+
?a
354+
EOS
355+
prev_opens, next_opens, min_depth = parse_by_line(code).last
356+
assert_equal([], prev_opens)
357+
assert_equal([], next_opens)
358+
assert_equal(0, min_depth)
359+
end
350360
end
351361
end

0 commit comments

Comments
 (0)