зеркало из https://github.com/github/ruby.git
parse.y: "nil" for defined? with empty expression
* parse.y (new_defined): remove all extra parentheses, and return "nil" for defined? with empty expression. [ruby-core:54024] [Bug #8224] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
7a7bb64464
Коммит
40370296c7
|
@ -1,3 +1,9 @@
|
|||
Sat Apr 6 02:30:28 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* parse.y (new_defined): remove all extra parentheses, and return
|
||||
"nil" for defined? with empty expression.
|
||||
[ruby-core:54024] [Bug #8224]
|
||||
|
||||
Sat Apr 6 02:06:04 2013 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||
|
||||
* ext/psych/lib/psych/visitors/to_ruby.rb: correctly register
|
||||
|
|
19
parse.y
19
parse.y
|
@ -369,6 +369,7 @@ static void fixpos(NODE*,NODE*);
|
|||
static int value_expr_gen(struct parser_params*,NODE*);
|
||||
static void void_expr_gen(struct parser_params*,NODE*);
|
||||
static NODE *remove_begin(NODE*);
|
||||
static NODE *remove_begin_all(NODE*);
|
||||
#define value_expr(node) value_expr_gen(parser, (node) = remove_begin(node))
|
||||
#define void_expr0(node) void_expr_gen(parser, (node))
|
||||
#define void_expr(node) void_expr0((node) = remove_begin(node))
|
||||
|
@ -438,6 +439,8 @@ static NODE *new_attr_op_assign_gen(struct parser_params *parser, NODE *lhs, ID
|
|||
static NODE *new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs);
|
||||
#define new_const_op_assign(lhs, op, rhs) new_const_op_assign_gen(parser, (lhs), (op), (rhs))
|
||||
|
||||
#define new_defined(expr) NEW_DEFINED(remove_begin_all(expr))
|
||||
|
||||
static NODE *match_op_gen(struct parser_params*,NODE*,NODE*);
|
||||
#define match_op(node1,node2) match_op_gen(parser, (node1), (node2))
|
||||
|
||||
|
@ -616,6 +619,8 @@ new_args_tail_gen(struct parser_params *parser, VALUE k, VALUE kr, VALUE b)
|
|||
}
|
||||
#define new_args_tail(k,kr,b) new_args_tail_gen(parser, (k),(kr),(b))
|
||||
|
||||
#define new_defined(expr) dispatch1(defined, (expr))
|
||||
|
||||
#define FIXME 0
|
||||
|
||||
#endif /* RIPPER */
|
||||
|
@ -2305,7 +2310,7 @@ arg : lhs '=' arg
|
|||
{
|
||||
/*%%%*/
|
||||
in_defined = 0;
|
||||
$$ = NEW_DEFINED($4);
|
||||
$$ = new_defined($4);
|
||||
/*%
|
||||
in_defined = 0;
|
||||
$$ = dispatch1(defined, $4);
|
||||
|
@ -2705,7 +2710,7 @@ primary : literal
|
|||
{
|
||||
/*%%%*/
|
||||
in_defined = 0;
|
||||
$$ = NEW_DEFINED($5);
|
||||
$$ = new_defined($5);
|
||||
/*%
|
||||
in_defined = 0;
|
||||
$$ = dispatch1(defined, $5);
|
||||
|
@ -8926,6 +8931,16 @@ remove_begin(NODE *node)
|
|||
return node;
|
||||
}
|
||||
|
||||
static NODE *
|
||||
remove_begin_all(NODE *node)
|
||||
{
|
||||
NODE **n = &node, *n1 = node;
|
||||
while (n1 && nd_type(n1) == NODE_BEGIN) {
|
||||
*n = n1 = n1->nd_body;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
static void
|
||||
reduce_nodes_gen(struct parser_params *parser, NODE **body)
|
||||
{
|
||||
|
|
|
@ -89,6 +89,13 @@ class TestDefined < Test::Unit::TestCase
|
|||
assert_equal("true", defined?(true))
|
||||
assert_equal("false", defined?(false))
|
||||
assert_equal("expression", defined?(1))
|
||||
|
||||
bug8224 = '[ruby-core:54024] [Bug #8224]'
|
||||
(1..3).each do |level|
|
||||
expr = "("*level+")"*level
|
||||
assert_equal("nil", eval("defined? #{expr}"), "#{bug8224} defined? #{expr}")
|
||||
assert_equal("nil", eval("defined?(#{expr})"), "#{bug8224} defined?(#{expr})")
|
||||
end
|
||||
end
|
||||
|
||||
def test_defined_impl_specific
|
||||
|
|
Загрузка…
Ссылка в новой задаче