Skip to content

Commit fb6a489

Browse files
committed
Revert "Method reference operator"
This reverts commit 67c5747. [Feature #16275]
1 parent b41a19f commit fb6a489

18 files changed

+5
-141
lines changed

Diff for: NEWS

-3
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,6 @@ sufficient information, see the ChangeLog file or Redmine
186186
# Previously parsed as: (a, b = raise) rescue [1, 2]
187187
# Now parsed as: a, b = (raise rescue [1, 2])
188188

189-
* Method reference operator, <code>.:</code> is introduced as an
190-
experimental feature. [Feature #12125] [Feature #13581]
191-
192189
* +yield+ in singleton class syntax is warned and will be deprecated later [Feature #15575].
193190

194191
* Argument forwarding by <code>(...)</code> is introduced. [Feature #16253]

Diff for: ast.c

-3
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,6 @@ node_children(rb_ast_t *ast, NODE *node)
432432
NEW_CHILD(ast, node->nd_args));
433433
case NODE_VCALL:
434434
return rb_ary_new_from_args(1, ID2SYM(node->nd_mid));
435-
case NODE_METHREF:
436-
return rb_ary_new_from_args(2, NEW_CHILD(ast, node->nd_recv),
437-
ID2SYM(node->nd_mid));
438435
case NODE_SUPER:
439436
return rb_ary_new_from_node_args(ast, 1, node->nd_args);
440437
case NODE_ZSUPER:

Diff for: compile.c

-9
Original file line numberDiff line numberDiff line change
@@ -4742,11 +4742,9 @@ defined_expr0(rb_iseq_t *iseq, LINK_ANCHOR *const ret,
47424742
case NODE_OPCALL:
47434743
case NODE_VCALL:
47444744
case NODE_FCALL:
4745-
case NODE_METHREF:
47464745
case NODE_ATTRASGN:{
47474746
const int explicit_receiver =
47484747
(type == NODE_CALL || type == NODE_OPCALL ||
4749-
type == NODE_METHREF ||
47504748
(type == NODE_ATTRASGN && !private_recv_p(node)));
47514749

47524750
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
84848482
}
84858483
break;
84868484
}
8487-
case NODE_METHREF:
8488-
CHECK(COMPILE(ret, "receiver", node->nd_recv));
8489-
ADD_ELEM(ret, &new_insn_body(iseq, line, BIN(methodref), 1, ID2SYM(node->nd_mid))->link);
8490-
if (popped) {
8491-
ADD_INSN(ret, line, pop);
8492-
}
8493-
break;
84948485
default:
84958486
UNKNOWN_NODE("iseq_compile_each", node, COMPILE_NG);
84968487
ng:

Diff for: defs/id.def

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ token_ops = %[\
130130
ANDOP &&
131131
OROP ||
132132
ANDDOT &.
133-
METHREF .:
134133
]
135134

136135
class KeywordError < RuntimeError

Diff for: ext/objspace/objspace.c

-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ count_nodes(int argc, VALUE *argv, VALUE os)
474474
COUNT_NODE(NODE_DSYM);
475475
COUNT_NODE(NODE_ATTRASGN);
476476
COUNT_NODE(NODE_LAMBDA);
477-
COUNT_NODE(NODE_METHREF);
478477
COUNT_NODE(NODE_ARYPTN);
479478
COUNT_NODE(NODE_HSHPTN);
480479
#undef COUNT_NODE

Diff for: ext/ripper/eventids2.c

-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ ripper_token2eventid(enum yytokentype tok)
261261
[tSTAR] = O(op),
262262
[tDSTAR] = O(op),
263263
[tANDDOT] = O(op),
264-
[tMETHREF] = O(op),
265264
[tSTRING_BEG] = O(tstring_beg),
266265
[tSTRING_CONTENT] = O(tstring_content),
267266
[tSTRING_DBEG] = O(embexpr_beg),

Diff for: insns.def

-11
Original file line numberDiff line numberDiff line change
@@ -719,17 +719,6 @@ checktype
719719
ret = (TYPE(val) == (int)type) ? Qtrue : Qfalse;
720720
}
721721

722-
/* get frozen method reference. */
723-
DEFINE_INSN
724-
methodref
725-
(ID id)
726-
(VALUE val)
727-
(VALUE ret)
728-
{
729-
ret = rb_obj_method(val, ID2SYM(id));
730-
RB_OBJ_FREEZE_RAW(ret);
731-
}
732-
733722
/**********************************************************/
734723
/* deal with control flow 1: class/module */
735724
/**********************************************************/

Diff for: lib/optparse.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,7 @@ def complete(typ, opt, icase = false, *pat)
17811781
visit(:complete, typ, opt, icase, *pat) {|o, *sw| return sw}
17821782
}
17831783
exc = ambiguous ? AmbiguousOption : InvalidOption
1784-
raise exc.new(opt, additional: self.:additional_message.curry[typ])
1784+
raise exc.new(opt, additional: self.method(:additional_message).curry[typ])
17851785
end
17861786
private :complete
17871787

Diff for: node.c

-9
Original file line numberDiff line numberDiff line change
@@ -954,15 +954,6 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
954954
F_NODE(nd_args, "arguments");
955955
return;
956956

957-
case NODE_METHREF:
958-
ANN("method reference");
959-
ANN("format: [nd_recv].:[nd_mid]");
960-
ANN("example: foo.:method");
961-
F_NODE(nd_recv, "receiver");
962-
LAST_NODE;
963-
F_ID(nd_mid, "method name");
964-
return;
965-
966957
case NODE_LAMBDA:
967958
ANN("lambda expression");
968959
ANN("format: -> [nd_body]");

Diff for: node.h

-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ enum node_type {
122122
NODE_DSYM,
123123
NODE_ATTRASGN,
124124
NODE_LAMBDA,
125-
NODE_METHREF,
126125
NODE_ARYPTN,
127126
NODE_HSHPTN,
128127
NODE_LAST
@@ -378,7 +377,6 @@ typedef struct RNode {
378377
#define NEW_PREEXE(b,loc) NEW_SCOPE(b,loc)
379378
#define NEW_POSTEXE(b,loc) NEW_NODE(NODE_POSTEXE,0,b,0,loc)
380379
#define NEW_ATTRASGN(r,m,a,loc) NEW_NODE(NODE_ATTRASGN,r,m,a,loc)
381-
#define NEW_METHREF(r,m,loc) NEW_NODE(NODE_METHREF,r,m,0,loc)
382380

383381
#define NODE_SPECIAL_REQUIRED_KEYWORD ((NODE *)-1)
384382
#define NODE_REQUIRED_KEYWORD_P(node) ((node)->nd_value == NODE_SPECIAL_REQUIRED_KEYWORD)

Diff for: parse.y

+1-27
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,6 @@ static int looking_at_eol_p(struct parser_params *p);
11141114
%token tRSHFT RUBY_TOKEN(RSHFT) ">>"
11151115
%token <id> tANDDOT RUBY_TOKEN(ANDDOT) "&."
11161116
%token <id> tCOLON2 RUBY_TOKEN(COLON2) "::"
1117-
%token <id> tMETHREF RUBY_TOKEN(METHREF) ".:"
11181117
%token tCOLON3 ":: at EXPR_BEG"
11191118
%token <id> tOP_ASGN "operator-assignment" /* +=, -= etc. */
11201119
%token tASSOC "=>"
@@ -3064,13 +3063,6 @@ primary : literal
30643063
/*% %*/
30653064
/*% ripper: retry! %*/
30663065
}
3067-
| primary_value tMETHREF operation2
3068-
{
3069-
/*%%%*/
3070-
$$ = NEW_METHREF($1, $3, &@$);
3071-
/*% %*/
3072-
/*% ripper: methref!($1, $3) %*/
3073-
}
30743066
;
30753067

30763068
primary_value : primary
@@ -9232,8 +9224,7 @@ parser_yylex(struct parser_params *p)
92329224
case '.': {
92339225
int is_beg = IS_BEG();
92349226
SET_LEX_STATE(EXPR_BEG);
9235-
switch (c = nextc(p)) {
9236-
case '.':
9227+
if ((c = nextc(p)) == '.') {
92379228
if ((c = nextc(p)) == '.') {
92389229
if (p->lex.paren_nest == 0 && looking_at_eol_p(p)) {
92399230
rb_warn0("... at EOL, should be parenthesized?");
@@ -9242,23 +9233,6 @@ parser_yylex(struct parser_params *p)
92429233
}
92439234
pushback(p, c);
92449235
return is_beg ? tBDOT2 : tDOT2;
9245-
case ':':
9246-
switch (c = nextc(p)) {
9247-
default:
9248-
if (!parser_is_identchar(p)) break;
9249-
/* fallthru */
9250-
case '!': case '%': case '&': case '*': case '+':
9251-
case '-': case '/': case '<': case '=': case '>':
9252-
case '[': case '^': case '`': case '|': case '~':
9253-
pushback(p, c);
9254-
SET_LEX_STATE(EXPR_DOT);
9255-
return tMETHREF;
9256-
case -1:
9257-
break;
9258-
}
9259-
pushback(p, c);
9260-
c = ':';
9261-
break;
92629236
}
92639237
pushback(p, c);
92649238
if (c != -1 && ISDIGIT(c)) {

Diff for: test/ripper/test_parser_events.rb

-7
Original file line numberDiff line numberDiff line change
@@ -443,13 +443,6 @@ def test_call
443443
assert_equal "[call(ref(self),&.,foo,[])]", tree
444444
end
445445

446-
def test_methref
447-
thru_methref = false
448-
tree = parse("obj.:foo", :on_methref) {thru_methref = true}
449-
assert_equal true, thru_methref
450-
assert_equal "[methref(vcall(obj),foo)]", tree
451-
end
452-
453446
def test_excessed_comma
454447
thru_excessed_comma = false
455448
parse("proc{|x,|}", :on_excessed_comma) {thru_excessed_comma = true}

Diff for: test/ripper/test_scanner_events.rb

-2
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,6 @@ def test_op
562562
scan('op', ':[]=')
563563
assert_equal ['&.'],
564564
scan('op', 'a&.f')
565-
assert_equal %w(.:),
566-
scan('op', 'obj.:foo')
567565
assert_equal [],
568566
scan('op', %q[`make all`])
569567
end

Diff for: test/ruby/test_ast.rb

-9
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,6 @@ def test_defs
264264
assert_equal(:SCOPE, defn.type)
265265
end
266266

267-
def test_methref
268-
node = RubyVM::AbstractSyntaxTree.parse("obj.:foo")
269-
_, _, body = *node.children
270-
assert_equal(:METHREF, body.type)
271-
recv, mid = body.children
272-
assert_equal(:VCALL, recv.type)
273-
assert_equal(:foo, mid)
274-
end
275-
276267
def test_dstr
277268
node = parse('"foo#{1}bar"')
278269
_, _, body = *node.children

Diff for: test/ruby/test_jit.rb

-7
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,6 @@ def test_compile_insn_checktype
482482
end;
483483
end
484484

485-
def test_compile_insn_methodref
486-
assert_compile_once("#{<<~"begin;"}\n#{<<~'end;'}", result_inspect: '"main"', insns: %i[methodref])
487-
begin;
488-
self.:inspect.call
489-
end;
490-
end
491-
492485
def test_compile_insn_inlinecache
493486
assert_compile_once('Struct', result_inspect: 'Struct', insns: %i[opt_getinlinecache opt_setinlinecache])
494487
end

Diff for: test/ruby/test_method.rb

-36
Original file line numberDiff line numberDiff line change
@@ -1125,42 +1125,6 @@ def f(x) x * 2 end
11251125
}
11261126
end
11271127

1128-
def test_method_reference_operator
1129-
m = 1.:succ
1130-
assert_predicate(m, :frozen?)
1131-
assert_equal(1.method(:succ), m)
1132-
assert_equal(2, m.())
1133-
m = 1.:+
1134-
assert_predicate(m, :frozen?)
1135-
assert_equal(1.method(:+), m)
1136-
assert_equal(42, m.(41))
1137-
m = 1.:-@
1138-
assert_predicate(m, :frozen?)
1139-
assert_equal(1.method(:-@), m)
1140-
assert_equal(-1, m.())
1141-
o = Object.new
1142-
def o.foo; 42; end
1143-
assert_predicate(o.:foo, :frozen?)
1144-
m = o.method(:foo)
1145-
assert_equal(m, o.:foo)
1146-
def o.method(m); nil; end
1147-
assert_equal(m, o.:foo)
1148-
assert_nil(o.method(:foo))
1149-
end
1150-
1151-
def test_method_reference_freeze_state
1152-
m = 1.:succ
1153-
assert_predicate(m, :frozen?, "dot-symbol method reference should be frozen")
1154-
m = 1.method(:succ)
1155-
assert_not_predicate(m, :frozen?, "#method method reference should not be frozen")
1156-
o = Object.new
1157-
def o.foo; 42; end
1158-
m = o.:foo
1159-
assert_predicate(m, :frozen?, "dot-symbol method reference should be frozen")
1160-
m = o.method(:foo)
1161-
assert_not_predicate(m, :frozen?, "#method method reference should not be frozen")
1162-
end
1163-
11641128
def test_umethod_bind_call
11651129
foo = Base.instance_method(:foo)
11661130
assert_equal(:base, foo.bind_call(Base.new))

Diff for: test/ruby/test_refinement.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def test_method_should_use_refinements
235235
meth.call(3)
236236
EOS
237237
assert_equal(:refine_pow, eval_using(MethodIntegerPowEx, "2.pow(3)"))
238-
assert_equal(:refine_pow, eval_using(MethodIntegerPowEx, "2.:pow.(3)"))
238+
assert_equal(:refine_pow, eval_using(MethodIntegerPowEx, "2.method(:pow).(3)"))
239239
end
240240

241241
module InstanceMethodIntegerPowEx

Diff for: test/ruby/test_syntax.rb

+2-11
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,6 @@ def test_do_block_in_cmdarg
9393
assert_valid_syntax("tap (proc do end)", __FILE__, bug9726)
9494
end
9595

96-
def test_methodref_literal
97-
assert_separately [], <<-EOS
98-
eval 'nil.:|;1'
99-
1000.times{eval 'nil.:|;1'}
100-
EOS
101-
end
102-
10396
def test_array_kwsplat_hash
10497
kw = {}
10598
h = {a: 1}
@@ -1014,10 +1007,8 @@ def test_invalid_literal_message
10141007
def test_fluent_dot
10151008
assert_valid_syntax("a\n.foo")
10161009
assert_valid_syntax("a\n&.foo")
1017-
assert_valid_syntax("a\n.:foo")
10181010
assert_valid_syntax("a #\n#\n.foo\n")
10191011
assert_valid_syntax("a #\n#\n&.foo\n")
1020-
assert_valid_syntax("a #\n#\n.:foo\n")
10211012
end
10221013

10231014
def test_safe_call_in_massign_lhs
@@ -1534,8 +1525,8 @@ def obj3.bar(*args, &block)
15341525
assert_warning(/\A\z|:(?!#{__LINE__+1})\d+: #{warning}/o) {
15351526
assert_equal([[], {}], obj.foo({}))
15361527
}
1537-
assert_equal(-1, obj.:foo.arity)
1538-
parameters = obj.:foo.parameters
1528+
assert_equal(-1, obj.method(:foo).arity)
1529+
parameters = obj.method(:foo).parameters
15391530
assert_equal(:rest, parameters.dig(0, 0))
15401531
assert_equal(:block, parameters.dig(1, 0))
15411532
end

0 commit comments

Comments
 (0)