diff options
-rw-r--r-- | parse.y | 17 | ||||
-rw-r--r-- | test/ruby/test_rubyoptions.rb | 6 |
2 files changed, 12 insertions, 11 deletions
@@ -738,7 +738,7 @@ PRINTF_ARGS(static void parser_compile_error(struct parser_params*, const char * static void token_info_push(struct parser_params*, const char *token, const rb_code_location_t *loc); static void token_info_pop(struct parser_params*, const char *token, const rb_code_location_t *loc); -static void token_info_warn(struct parser_params *p, const char *token, token_info *ptinfo_beg, const rb_code_location_t *loc); +static void token_info_warn(struct parser_params *p, const char *token, token_info *ptinfo_beg, int same, const rb_code_location_t *loc); %} %pure-parser @@ -2731,31 +2731,31 @@ k_do_block : keyword_do_block k_rescue : keyword_rescue { - token_info_warn(p, "rescue", p->token_info, &@$); + token_info_warn(p, "rescue", p->token_info, 1, &@$); } ; k_ensure : keyword_ensure { - token_info_warn(p, "ensure", p->token_info, &@$); + token_info_warn(p, "ensure", p->token_info, 1, &@$); } ; k_when : keyword_when { - token_info_warn(p, "when", p->token_info, &@$); + token_info_warn(p, "when", p->token_info, 0, &@$); } ; k_else : keyword_else { - token_info_warn(p, "else", p->token_info, &@$); + token_info_warn(p, "else", p->token_info, 1, &@$); } ; k_elsif : keyword_elsif { - token_info_warn(p, "elsif", p->token_info, &@$); + token_info_warn(p, "elsif", p->token_info, 1, &@$); } ; @@ -4533,12 +4533,12 @@ token_info_pop(struct parser_params *p, const char *token, const rb_code_locatio p->token_info = ptinfo_beg->next; /* indentation check of matched keywords (begin..end, if..end, etc.) */ - token_info_warn(p, token, ptinfo_beg, loc); + token_info_warn(p, token, ptinfo_beg, 1, loc); xfree(ptinfo_beg); } static void -token_info_warn(struct parser_params *p, const char *token, token_info *ptinfo_beg, const rb_code_location_t *loc) +token_info_warn(struct parser_params *p, const char *token, token_info *ptinfo_beg, int same, const rb_code_location_t *loc) { token_info ptinfo_end_body, *ptinfo_end = &ptinfo_end_body; if (!p->token_info_enabled) return; @@ -4547,6 +4547,7 @@ token_info_warn(struct parser_params *p, const char *token, token_info *ptinfo_b if (ptinfo_beg->linenum == ptinfo_end->linenum) return; /* ignore one-line block */ if (ptinfo_beg->nonspc || ptinfo_end->nonspc) return; /* ignore keyword in the middle of a line */ if (ptinfo_beg->column == ptinfo_end->column) return; /* the indents are matched */ + if (!same && ptinfo_beg->column < ptinfo_end->column) return; rb_warn3L(ptinfo_end->linenum, "mismatched indentations at '%s' with '%s' at %d", WARN_S(token), WARN_S(ptinfo_beg->token), WARN_I(ptinfo_beg->linenum)); diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 0f608cd8a5..ddfd5f1883 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -450,13 +450,13 @@ class TestRubyOptions < Test::Unit::TestCase ["begin", "rescue ; end"], ["begin rescue", "else ; end"], ["begin", "ensure ; end"], - ["case nil", "when true; end"], + [" case nil", "when true; end"], ["case nil; when true", "end"], ].each do |b, e = 'end'| src = ["#{b}\n", " #{e}\n"] - k = b[/\A\S+/] - e = e[/\A\S+/] + k = b[/\A\s*(\S+)/, 1] + e = e[/\A\s*(\S+)/, 1] a.for("no directives with #{b}") do err = ["#{t.path}:2: warning: mismatched indentations at '#{e}' with '#{k}' at 1"] |