[前][次][番号順一覧][スレッド一覧]

ruby-changes:47047

From: nobu <ko1@a...>
Date: Fri, 23 Jun 2017 20:56:53 +0900 (JST)
Subject: [ruby-changes:47047] nobu:r59162 (trunk): parse.y: should not warn op method call

nobu	2017-06-23 20:56:48 +0900 (Fri, 23 Jun 2017)

  New Revision: 59162

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59162

  Log:
    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]

  Modified files:
    trunk/compile.c
    trunk/node.c
    trunk/node.h
    trunk/parse.y
    trunk/test/ruby/test_parse.rb
Index: node.c
===================================================================
--- node.c	(revision 59161)
+++ node.c	(revision 59162)
@@ -475,6 +475,7 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L475
 	break;
 
       case NODE_CALL:
+      case NODE_OPCALL:
 	ANN("method invocation");
 	ANN("format: [nd_recv].[nd_mid]([nd_args])");
 	ANN("example: obj.foo(1)");
Index: node.h
===================================================================
--- node.h	(revision 59161)
+++ node.h	(revision 59162)
@@ -92,6 +92,8 @@ enum node_type { https://github.com/ruby/ruby/blob/trunk/node.h#L92
 #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 { https://github.com/ruby/ruby/blob/trunk/node.h#L420
 #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)
Index: test/ruby/test_parse.rb
===================================================================
--- test/ruby/test_parse.rb	(revision 59161)
+++ test/ruby/test_parse.rb	(revision 59162)
@@ -761,6 +761,7 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L761
     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")
Index: parse.y
===================================================================
--- parse.y	(revision 59161)
+++ parse.y	(revision 59162)
@@ -8837,14 +8837,14 @@ call_bin_op_gen(struct parser_params *pa https://github.com/ruby/ruby/blob/trunk/parse.y#L8837
 {
     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 *pars https://github.com/ruby/ruby/blob/trunk/parse.y#L9523
 
     if (!node) return;
     switch (nd_type(node)) {
-      case NODE_CALL:
+      case NODE_OPCALL:
 	switch (node->nd_mid) {
 	  case '+':
 	  case '-':
Index: compile.c
===================================================================
--- compile.c	(revision 59161)
+++ compile.c	(revision 59162)
@@ -3644,11 +3644,12 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L3644
 
 	/* 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 https://github.com/ruby/ruby/blob/trunk/compile.c#L5238
 	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 https://github.com/ruby/ruby/blob/trunk/compile.c#L5365
 	}
 #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);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]