mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: should not warn op method call
* parse.y (void_expr_gen): should warn operator expression style calls only, but not method style calls. [Fix GH-1660] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59162 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d391697331
commit
af4ba5c12a
5 changed files with 12 additions and 5 deletions
|
@ -3644,11 +3644,12 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *const ret,
|
|||
|
||||
/* method dispatch */
|
||||
case NODE_CALL:
|
||||
case NODE_OPCALL:
|
||||
case NODE_VCALL:
|
||||
case NODE_FCALL:
|
||||
case NODE_ATTRASGN:{
|
||||
const int explicit_receiver =
|
||||
(type == NODE_CALL ||
|
||||
(type == NODE_CALL || type == NODE_OPCALL ||
|
||||
(type == NODE_ATTRASGN && !private_recv_p(node)));
|
||||
|
||||
if (!lfinish[1] && (node->nd_args || explicit_receiver)) {
|
||||
|
@ -5237,6 +5238,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popp
|
|||
break;
|
||||
}
|
||||
case NODE_CALL:
|
||||
case NODE_OPCALL:
|
||||
/* optimization shortcut
|
||||
* "literal".freeze -> opt_str_freeze("literal")
|
||||
*/
|
||||
|
@ -5363,7 +5365,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popp
|
|||
}
|
||||
#endif
|
||||
/* receiver */
|
||||
if (type == NODE_CALL || type == NODE_QCALL) {
|
||||
if (type == NODE_CALL || type == NODE_OPCALL || type == NODE_QCALL) {
|
||||
CHECK(COMPILE(recv, "recv", node->nd_recv));
|
||||
if (type == NODE_QCALL) {
|
||||
lskip = NEW_LABEL(line);
|
||||
|
|
1
node.c
1
node.c
|
@ -475,6 +475,7 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node)
|
|||
break;
|
||||
|
||||
case NODE_CALL:
|
||||
case NODE_OPCALL:
|
||||
ANN("method invocation");
|
||||
ANN("format: [nd_recv].[nd_mid]([nd_args])");
|
||||
ANN("example: obj.foo(1)");
|
||||
|
|
3
node.h
3
node.h
|
@ -92,6 +92,8 @@ enum node_type {
|
|||
#define NODE_OP_CDECL NODE_OP_CDECL
|
||||
NODE_CALL,
|
||||
#define NODE_CALL NODE_CALL
|
||||
NODE_OPCALL,
|
||||
#define NODE_OPCALL NODE_OPCALL
|
||||
NODE_FCALL,
|
||||
#define NODE_FCALL NODE_FCALL
|
||||
NODE_VCALL,
|
||||
|
@ -418,6 +420,7 @@ typedef struct RNode {
|
|||
#define NEW_DSYM(s) NEW_NODE(NODE_DSYM,s,0,0)
|
||||
#define NEW_EVSTR(n) NEW_NODE(NODE_EVSTR,0,(n),0)
|
||||
#define NEW_CALL(r,m,a) NEW_NODE(NODE_CALL,r,m,a)
|
||||
#define NEW_OPCALL(r,m,a) NEW_NODE(NODE_OPCALL,r,m,a)
|
||||
#define NEW_FCALL(m,a) NEW_NODE(NODE_FCALL,0,m,a)
|
||||
#define NEW_VCALL(m) NEW_NODE(NODE_VCALL,0,m,0)
|
||||
#define NEW_SUPER(a) NEW_NODE(NODE_SUPER,0,0,a)
|
||||
|
|
6
parse.y
6
parse.y
|
@ -8837,14 +8837,14 @@ call_bin_op_gen(struct parser_params *parser, NODE *recv, ID id, NODE *arg1)
|
|||
{
|
||||
value_expr(recv);
|
||||
value_expr(arg1);
|
||||
return NEW_CALL(recv, id, NEW_LIST(arg1));
|
||||
return NEW_OPCALL(recv, id, NEW_LIST(arg1));
|
||||
}
|
||||
|
||||
static NODE *
|
||||
call_uni_op_gen(struct parser_params *parser, NODE *recv, ID id)
|
||||
{
|
||||
value_expr(recv);
|
||||
return NEW_CALL(recv, id, 0);
|
||||
return NEW_OPCALL(recv, id, 0);
|
||||
}
|
||||
|
||||
static NODE*
|
||||
|
@ -9523,7 +9523,7 @@ void_expr_gen(struct parser_params *parser, NODE *node)
|
|||
|
||||
if (!node) return;
|
||||
switch (nd_type(node)) {
|
||||
case NODE_CALL:
|
||||
case NODE_OPCALL:
|
||||
switch (node->nd_mid) {
|
||||
case '+':
|
||||
case '-':
|
||||
|
|
|
@ -761,6 +761,7 @@ x = __ENCODING__
|
|||
x = x = 1
|
||||
assert_nil eval("x; nil")
|
||||
assert_nil eval("1+1; nil")
|
||||
assert_nil eval("1.+(1); nil")
|
||||
assert_nil eval("TestParse; nil")
|
||||
assert_nil eval("::TestParse; nil")
|
||||
assert_nil eval("x..x; nil")
|
||||
|
|
Loading…
Reference in a new issue