parse.y: dynamic const assign_error in ripper
* parse.y (mlhs_node): dynamic constant assignment in massign should cause assign_error, like as single assign and backref assignment in massign. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
418c46f284
commit
be7c04e197
8
parse.y
8
parse.y
@ -1672,9 +1672,10 @@ mlhs_node : user_variable
|
|||||||
yyerror("dynamic constant assignment");
|
yyerror("dynamic constant assignment");
|
||||||
$$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
|
$$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
|
||||||
/*%
|
/*%
|
||||||
if (in_def || in_single)
|
|
||||||
yyerror("dynamic constant assignment");
|
|
||||||
$$ = dispatch2(const_path_field, $1, $3);
|
$$ = dispatch2(const_path_field, $1, $3);
|
||||||
|
if (in_def || in_single) {
|
||||||
|
$$ = dispatch1(assign_error, $$);
|
||||||
|
}
|
||||||
%*/
|
%*/
|
||||||
}
|
}
|
||||||
| tCOLON3 tCONSTANT
|
| tCOLON3 tCONSTANT
|
||||||
@ -1685,6 +1686,9 @@ mlhs_node : user_variable
|
|||||||
$$ = NEW_CDECL(0, 0, NEW_COLON3($2));
|
$$ = NEW_CDECL(0, 0, NEW_COLON3($2));
|
||||||
/*%
|
/*%
|
||||||
$$ = dispatch1(top_const_field, $2);
|
$$ = dispatch1(top_const_field, $2);
|
||||||
|
if (in_def || in_single) {
|
||||||
|
$$ = dispatch1(assign_error, $$);
|
||||||
|
}
|
||||||
%*/
|
%*/
|
||||||
}
|
}
|
||||||
| backref
|
| backref
|
||||||
|
@ -183,29 +183,48 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_assign_error
|
def test_assign_error
|
||||||
|
# for test_coverage
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_assign_error_backref
|
||||||
thru_assign_error = false
|
thru_assign_error = false
|
||||||
parse('$` = 1', :on_assign_error) {thru_assign_error = true}
|
parse('$` = 1', :on_assign_error) {thru_assign_error = true}
|
||||||
assert_equal true, thru_assign_error
|
assert_equal true, thru_assign_error
|
||||||
thru_assign_error = false
|
thru_assign_error = false
|
||||||
parse('$`, _ = 1', :on_assign_error) {thru_assign_error = true}
|
parse('$`, _ = 1', :on_assign_error) {thru_assign_error = true}
|
||||||
assert_equal true, thru_assign_error
|
assert_equal true, thru_assign_error
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_assign_error_const_qualified
|
||||||
thru_assign_error = false
|
thru_assign_error = false
|
||||||
parse('self::X = 1', :on_assign_error) {thru_assign_error = true}
|
parse('self::X = 1', :on_assign_error) {thru_assign_error = true}
|
||||||
assert_equal false, thru_assign_error
|
assert_equal false, thru_assign_error
|
||||||
parse('def m\n self::X = 1\nend', :on_assign_error) {thru_assign_error = true}
|
parse("def m\n self::X = 1\nend", :on_assign_error) {thru_assign_error = true}
|
||||||
assert_equal true, thru_assign_error
|
assert_equal true, thru_assign_error
|
||||||
|
thru_assign_error = false
|
||||||
|
parse("def m\n self::X, a = 1, 2\nend", :on_assign_error) {thru_assign_error = true}
|
||||||
|
assert_equal true, thru_assign_error
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_assign_error_const
|
||||||
thru_assign_error = false
|
thru_assign_error = false
|
||||||
parse('X = 1', :on_assign_error) {thru_assign_error = true}
|
parse('X = 1', :on_assign_error) {thru_assign_error = true}
|
||||||
assert_equal false, thru_assign_error
|
assert_equal false, thru_assign_error
|
||||||
parse('def m\n X = 1\nend', :on_assign_error) {thru_assign_error = true}
|
parse("def m\n X = 1\nend", :on_assign_error) {thru_assign_error = true}
|
||||||
assert_equal true, thru_assign_error
|
assert_equal true, thru_assign_error
|
||||||
|
thru_assign_error = false
|
||||||
|
parse("def m\n X, a = 1, 2\nend", :on_assign_error) {thru_assign_error = true}
|
||||||
|
assert_equal true, thru_assign_error
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_assign_error_const_toplevel
|
||||||
thru_assign_error = false
|
thru_assign_error = false
|
||||||
parse('::X = 1', :on_assign_error) {thru_assign_error = true}
|
parse('::X = 1', :on_assign_error) {thru_assign_error = true}
|
||||||
assert_equal false, thru_assign_error
|
assert_equal false, thru_assign_error
|
||||||
parse('def m\n ::X = 1\nend', :on_assign_error) {thru_assign_error = true}
|
parse("def m\n ::X = 1\nend", :on_assign_error) {thru_assign_error = true}
|
||||||
|
assert_equal true, thru_assign_error
|
||||||
|
thru_assign_error = false
|
||||||
|
parse("def m\n ::X, a = 1, 2\nend", :on_assign_error) {thru_assign_error = true}
|
||||||
assert_equal true, thru_assign_error
|
assert_equal true, thru_assign_error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user