ruby-changes:68237
From: Nobuyoshi <ko1@a...>
Date: Mon, 4 Oct 2021 12:20:37 +0900 (JST)
Subject: [ruby-changes:68237] 28392d3045 (master): The same warning for static symbol literal
https://git.ruby-lang.org/ruby.git/commit/?id=28392d3045 From 28392d30451bbf13cdacf6b745eb4f5147741bdf Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 4 Oct 2021 12:15:27 +0900 Subject: The same warning for static symbol literal --- parse.y | 4 ++++ test/ruby/test_syntax.rb | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/parse.y b/parse.y index 189731b45c..d7261a008d 100644 --- a/parse.y +++ b/parse.y @@ -11758,6 +11758,7 @@ cond0(struct parser_params *p, NODE *node, enum cond_type type, const YYLTYPE *l https://github.com/ruby/ruby/blob/trunk/parse.y#L11758 break; case NODE_DSYM: + warn_symbol: SWITCH_BY_COND_TYPE(type, warning, "symbol ") break; @@ -11770,6 +11771,9 @@ cond0(struct parser_params *p, NODE *node, enum cond_type type, const YYLTYPE *l https://github.com/ruby/ruby/blob/trunk/parse.y#L11771 node->nd_lit == Qfalse) { /* booleans are OK, e.g., while true */ } + else if (SYMBOL_P(node->nd_lit)) { + goto warn_symbol; + } else { SWITCH_BY_COND_TYPE(type, warning, "") } diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index bf59ee5379..667eb205dc 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1061,16 +1061,16 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L1061 end def test_warning_literal_in_condition - assert_warn(/literal in condition/) do + assert_warn(/string literal in condition/) do eval('1 if ""') end - assert_warn(/literal in condition/) do + assert_warn(/regex literal in condition/) do eval('1 if //') end assert_warning(/literal in condition/) do eval('1 if 1') end - assert_warning(/literal in condition/) do + assert_warning(/symbol literal in condition/) do eval('1 if :foo') end assert_warning(/symbol literal in condition/) do -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/