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

ruby-changes:58747

From: Nobuyoshi <ko1@a...>
Date: Tue, 12 Nov 2019 17:26:27 +0900 (JST)
Subject: [ruby-changes:58747] fb6a489af2 (master): Revert "Method reference operator"

https://git.ruby-lang.org/ruby.git/commit/?id=fb6a489af2

From fb6a489af2765a3b56e301adf0019af6bbad6156 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 24 Oct 2019 01:06:59 +0900
Subject: Revert "Method reference operator"

This reverts commit 67c574736912003c377218153f9d3b9c0c96a17b.
[Feature #16275]

diff --git a/NEWS b/NEWS
index 893fb6e..14e8fd2 100644
--- a/NEWS
+++ b/NEWS
@@ -186,9 +186,6 @@ sufficient information, see the ChangeLog file or Redmine https://github.com/ruby/ruby/blob/trunk/NEWS#L186
     # Previously parsed as: (a, b = raise) rescue [1, 2]
     # Now parsed as:         a, b = (raise rescue [1, 2])
 
-* Method reference operator, <code>.:</code> is introduced as an
-  experimental feature.  [Feature #12125] [Feature #13581]
-
 * +yield+ in singleton class syntax is warned and will be deprecated later [Feature #15575].
 
 * Argument forwarding by <code>(...)</code> is introduced. [Feature #16253]
diff --git a/ast.c b/ast.c
index 236560b..1133fb8 100644
--- a/ast.c
+++ b/ast.c
@@ -432,9 +432,6 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L432
                                     NEW_CHILD(ast, node->nd_args));
       case NODE_VCALL:
         return rb_ary_new_from_args(1, ID2SYM(node->nd_mid));
-      case NODE_METHREF:
-        return rb_ary_new_from_args(2, NEW_CHILD(ast, node->nd_recv),
-                                    ID2SYM(node->nd_mid));
       case NODE_SUPER:
         return rb_ary_new_from_node_args(ast, 1, node->nd_args);
       case NODE_ZSUPER:
diff --git a/compile.c b/compile.c
index 8c83903..b45aaef 100644
--- a/compile.c
+++ b/compile.c
@@ -4742,11 +4742,9 @@ defined_expr0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, https://github.com/ruby/ruby/blob/trunk/compile.c#L4742
       case NODE_OPCALL:
       case NODE_VCALL:
       case NODE_FCALL:
-      case NODE_METHREF:
       case NODE_ATTRASGN:{
 	const int explicit_receiver =
 	    (type == NODE_CALL || type == NODE_OPCALL ||
-             type == NODE_METHREF ||
 	     (type == NODE_ATTRASGN && !private_recv_p(node)));
 
 	if (!lfinish[1] && (node->nd_args || explicit_receiver)) {
@@ -8484,13 +8482,6 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in https://github.com/ruby/ruby/blob/trunk/compile.c#L8482
 	}
 	break;
       }
-      case NODE_METHREF:
-        CHECK(COMPILE(ret, "receiver", node->nd_recv));
-        ADD_ELEM(ret, &new_insn_body(iseq, line, BIN(methodref), 1, ID2SYM(node->nd_mid))->link);
-        if (popped) {
-            ADD_INSN(ret, line, pop);
-        }
-        break;
       default:
 	UNKNOWN_NODE("iseq_compile_each", node, COMPILE_NG);
       ng:
diff --git a/defs/id.def b/defs/id.def
index a35b5d5..fc7a04f 100644
--- a/defs/id.def
+++ b/defs/id.def
@@ -130,7 +130,6 @@ token_ops = %[\ https://github.com/ruby/ruby/blob/trunk/defs/id.def#L130
   ANDOP         &&
   OROP          ||
   ANDDOT        &.
-  METHREF       .:
 ]
 
 class KeywordError < RuntimeError
diff --git a/ext/objspace/objspace.c b/ext/objspace/objspace.c
index 927c5b5..311e687 100644
--- a/ext/objspace/objspace.c
+++ b/ext/objspace/objspace.c
@@ -474,7 +474,6 @@ count_nodes(int argc, VALUE *argv, VALUE os) https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L474
 		COUNT_NODE(NODE_DSYM);
 		COUNT_NODE(NODE_ATTRASGN);
 		COUNT_NODE(NODE_LAMBDA);
-                COUNT_NODE(NODE_METHREF);
                 COUNT_NODE(NODE_ARYPTN);
                 COUNT_NODE(NODE_HSHPTN);
 #undef COUNT_NODE
diff --git a/ext/ripper/eventids2.c b/ext/ripper/eventids2.c
index 4ab8c4c..cdac208 100644
--- a/ext/ripper/eventids2.c
+++ b/ext/ripper/eventids2.c
@@ -261,7 +261,6 @@ ripper_token2eventid(enum yytokentype tok) https://github.com/ruby/ruby/blob/trunk/ext/ripper/eventids2.c#L261
         [tSTAR] 		= O(op),
         [tDSTAR]		= O(op),
         [tANDDOT]		= O(op),
-        [tMETHREF]		= O(op),
         [tSTRING_BEG]		= O(tstring_beg),
         [tSTRING_CONTENT]	= O(tstring_content),
         [tSTRING_DBEG]		= O(embexpr_beg),
diff --git a/insns.def b/insns.def
index 1333c09..df50580 100644
--- a/insns.def
+++ b/insns.def
@@ -719,17 +719,6 @@ checktype https://github.com/ruby/ruby/blob/trunk/insns.def#L719
     ret = (TYPE(val) == (int)type) ? Qtrue : Qfalse;
 }
 
-/* get frozen method reference. */
-DEFINE_INSN
-methodref
-(ID id)
-(VALUE val)
-(VALUE ret)
-{
-    ret = rb_obj_method(val, ID2SYM(id));
-    RB_OBJ_FREEZE_RAW(ret);
-}
-
 /**********************************************************/
 /* deal with control flow 1: class/module                 */
 /**********************************************************/
diff --git a/lib/optparse.rb b/lib/optparse.rb
index b6d7170..614ebc3 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -1781,7 +1781,7 @@ XXX https://github.com/ruby/ruby/blob/trunk/lib/optparse.rb#L1781
       visit(:complete, typ, opt, icase, *pat) {|o, *sw| return sw}
     }
     exc = ambiguous ? AmbiguousOption : InvalidOption
-    raise exc.new(opt, additional: self.:additional_message.curry[typ])
+    raise exc.new(opt, additional: self.method(:additional_message).curry[typ])
   end
   private :complete
 
diff --git a/node.c b/node.c
index 6477446..3514060 100644
--- a/node.c
+++ b/node.c
@@ -954,15 +954,6 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node) https://github.com/ruby/ruby/blob/trunk/node.c#L954
 	F_NODE(nd_args, "arguments");
 	return;
 
-      case NODE_METHREF:
-        ANN("method reference");
-        ANN("format: [nd_recv].:[nd_mid]");
-        ANN("example: foo.:method");
-        F_NODE(nd_recv, "receiver");
-        LAST_NODE;
-        F_ID(nd_mid, "method name");
-        return;
-
       case NODE_LAMBDA:
 	ANN("lambda expression");
 	ANN("format: -> [nd_body]");
diff --git a/node.h b/node.h
index 8f43f45..79fa29d 100644
--- a/node.h
+++ b/node.h
@@ -122,7 +122,6 @@ enum node_type { https://github.com/ruby/ruby/blob/trunk/node.h#L122
     NODE_DSYM,
     NODE_ATTRASGN,
     NODE_LAMBDA,
-    NODE_METHREF,
     NODE_ARYPTN,
     NODE_HSHPTN,
     NODE_LAST
@@ -378,7 +377,6 @@ typedef struct RNode { https://github.com/ruby/ruby/blob/trunk/node.h#L377
 #define NEW_PREEXE(b,loc) NEW_SCOPE(b,loc)
 #define NEW_POSTEXE(b,loc) NEW_NODE(NODE_POSTEXE,0,b,0,loc)
 #define NEW_ATTRASGN(r,m,a,loc) NEW_NODE(NODE_ATTRASGN,r,m,a,loc)
-#define NEW_METHREF(r,m,loc) NEW_NODE(NODE_METHREF,r,m,0,loc)
 
 #define NODE_SPECIAL_REQUIRED_KEYWORD ((NODE *)-1)
 #define NODE_REQUIRED_KEYWORD_P(node) ((node)->nd_value == NODE_SPECIAL_REQUIRED_KEYWORD)
diff --git a/parse.y b/parse.y
index 6d05644..57b97a9 100644
--- a/parse.y
+++ b/parse.y
@@ -1114,7 +1114,6 @@ static int looking_at_eol_p(struct parser_params *p); https://github.com/ruby/ruby/blob/trunk/parse.y#L1114
 %token tRSHFT		RUBY_TOKEN(RSHFT)  ">>"
 %token <id> tANDDOT	RUBY_TOKEN(ANDDOT) "&."
 %token <id> tCOLON2	RUBY_TOKEN(COLON2) "::"
-%token <id> tMETHREF	RUBY_TOKEN(METHREF) ".:"
 %token tCOLON3		":: at EXPR_BEG"
 %token <id> tOP_ASGN	"operator-assignment" /* +=, -=  etc. */
 %token tASSOC		"=>"
@@ -3064,13 +3063,6 @@ primary		: literal https://github.com/ruby/ruby/blob/trunk/parse.y#L3063
 		    /*% %*/
 		    /*% ripper: retry! %*/
 		    }
-		| primary_value tMETHREF operation2
-		    {
-		    /*%%%*/
-			$$ = NEW_METHREF($1, $3, &@$);
-		    /*% %*/
-		    /*% ripper: methref!($1, $3) %*/
-		    }
 		;
 
 primary_value	: primary
@@ -9232,8 +9224,7 @@ parser_yylex(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L9224
       case '.': {
         int is_beg = IS_BEG();
 	SET_LEX_STATE(EXPR_BEG);
-	switch (c = nextc(p)) {
-	  case '.':
+	if ((c = nextc(p)) == '.') {
 	    if ((c = nextc(p)) == '.') {
 		if (p->lex.paren_nest == 0 && looking_at_eol_p(p)) {
 		    rb_warn0("... at EOL, should be parenthesized?");
@@ -9242,23 +9233,6 @@ parser_yylex(struct parser_params *p) https://github.com/ruby/ruby/blob/trunk/parse.y#L9233
 	    }
 	    pushback(p, c);
 	    return is_beg ? tBDOT2 : tDOT2;
-	  case ':':
-	    switch (c = nextc(p)) {
-	      default:
-		if (!parser_is_identchar(p)) break;
-		/* fallthru */
-	      case '!': case '%': case '&': case '*': case '+':
-	      case '-': case '/': case '<': case '=': case '>':
-	      case '[': case '^': case '`': case '|': case '~':
-		pushback(p, c);
-		SET_LEX_STATE(EXPR_DOT);
-		return tMETHREF;
-	      case -1:
-		break;
-	    }
-	    pushback(p, c);
-	    c = ':';
-	    break;
 	}
 	pushback(p, c);
 	if (c != -1 && ISDIGIT(c)) {
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index 1be2833..feb3db0 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -443,13 +443,6 @@ class TestRipper::ParserEvents < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_parser_events.rb#L443
     assert_equal "[call(ref(self),&.,foo,[])]", tree
   end
 
-  def test_methref
-    thru_methref = false
-    tree = parse("obj.:foo", :on_methref) {thru_methref = true}
-    assert_equal true, thru_methref
-    assert_equal "[methref(vcall(obj),foo)]", tree
-  end
-
   def test_excessed_comma
     thru_excessed_comma = false
     parse("proc{|x,|}", :on_excessed_comma) {thru_excessed_comma = true}
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb
index 641310b..d2f8479 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -562,8 +562,6 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ripper/test_scanner_events.rb#L562
                  scan('op', ':[]=')
     assert_equal ['&.'],
                  scan('op', 'a&.f')
-    assert_equal %w(.:),
-                 scan('op', 'obj.:foo')
     assert_equal [],
                  scan('op', %q[`make all`])
   end
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb
index a4c18d0..4c15665 100644
--- a/test/ruby/test_ast.rb
+++ b/test/ruby/test_ast.rb
@@ -264,15 +264,6 @@ class  (... truncated)

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

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