diff --git a/parse.y b/parse.y index 4daefb4a9c..c1919901f6 100644 --- a/parse.y +++ b/parse.y @@ -1835,6 +1835,10 @@ get_nd_value(struct parser_params *p, NODE *node) return RNODE_DASGN(node)->nd_value; case NODE_MASGN: return RNODE_MASGN(node)->nd_value; + case NODE_CVASGN: + return RNODE_CVASGN(node)->nd_value; + case NODE_CDECL: + return RNODE_CDECL(node)->nd_value; default: compile_error(p, "unexpected node: %s", parser_node_name(nd_type(node))); return 0; @@ -14044,6 +14048,8 @@ assign_in_cond(struct parser_params *p, NODE *node) case NODE_DASGN: case NODE_GASGN: case NODE_IASGN: + case NODE_CVASGN: + case NODE_CDECL: break; default: diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index 959bfe8a5b..cc65f3b849 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -895,12 +895,14 @@ x = __ENCODING__ end def test_assign_in_conditional + # multiple assignment assert_warning(/`= literal' in conditional/) do eval <<-END, nil, __FILE__, __LINE__+1 (x, y = 1, 2) ? 1 : 2 END end + # instance variable assignment assert_warning(/`= literal' in conditional/) do eval <<-END, nil, __FILE__, __LINE__+1 if @x = true @@ -910,6 +912,71 @@ x = __ENCODING__ end END end + + # local variable assignment + assert_warning(/`= literal' in conditional/) do + eval <<-END, nil, __FILE__, __LINE__+1 + def m + if x = true + 1 + else + 2 + end + end + END + end + + # global variable assignment + assert_separately([], <<-RUBY) + assert_warning(/`= literal' in conditional/) do + eval <<-END, nil, __FILE__, __LINE__+1 + if $x = true + 1 + else + 2 + end + END + end + RUBY + + # dynamic variable assignment + assert_warning(/`= literal' in conditional/) do + eval <<-END, nil, __FILE__, __LINE__+1 + y = 1 + + 1.times do + if y = true + 1 + else + 2 + end + end + END + end + + # class variable assignment + assert_warning(/`= literal' in conditional/) do + eval <<-END, nil, __FILE__, __LINE__+1 + c = Class.new + class << c + if @@a = 1 + end + end + END + end + + # constant declaration + assert_separately([], <<-RUBY) + assert_warning(/`= literal' in conditional/) do + eval <<-END, nil, __FILE__, __LINE__+1 + if Const = true + 1 + else + 2 + end + END + end + RUBY end def test_literal_in_conditional