8000 [ripper] fix mismatched indentations warning [Bug #16981] · github/ruby@263b941 · GitHub
[go: up one dir, main page]

Skip to content

Commit 263b941

Browse files
committed
[ripper] fix mismatched indentations warning [Bug #16981]
The scanner location has to be set from `lex.ptok` before it is flushed by dispatching the scanner event.
1 parent 7f29e34 commit 263b941

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

parse.y

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9662,16 +9662,17 @@ yylex(YYSTYPE *lval, YYLTYPE *yylloc, struct parser_params *p)
96629662
p->lval = lval;
96639663
lval->val = Qundef;
96649664
t = parser_yylex(p);
9665-
if (has_delayed_token(p))
9666-
dispatch_delayed_token(p, t);
9667-
else if (t != 0)
9668-
dispatch_scan_event(p, t);
96699665

96709666
if (p->lex.strterm && (p->lex.strterm->flags & STRTERM_HEREDOC))
96719667
RUBY_SET_YYLLOC_FROM_STRTERM_HEREDOC(*yylloc);
96729668
else
96739669
RUBY_SET_YYLLOC(*yylloc);
96749670

9671+
if (has_delayed_token(p))
9672+
dispatch_delayed_token(p, t);
9673+
else if (t != 0)
9674+
dispatch_scan_event(p, t);
9675+
96759676
return t;
96769677
}
96779678

test/ripper/test_parser_events.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,12 @@ def test_warn_cr_in_middle
15381538
assert_match(/encountered/, fmt)
15391539
end
15401540

1541+
def test_warn_mismatched_indentations
1542+
fmt, tokend, tokbeg, line = assert_warning("") {break warn("if true\n end\n")}
1543+
assert_match(/mismatched indentations/, fmt)
1544+
assert_equal(["if", "end", 1], [tokbeg, tokend, line])
1545+
end
1546+
15411547
def test_in
15421548
thru_in = false
15431549
parse('case 0; in 0; end', :on_in) {thru_in = true}

0 commit comments

Comments
 (0)
0