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

ruby-changes:60871

From: Nobuyoshi <ko1@a...>
Date: Wed, 22 Apr 2020 22:01:10 +0900 (JST)
Subject: [ruby-changes:60871] 1997e10f6c (master): Made parentheses mandatory in endless method defition

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

From 1997e10f6caeae49660ceb9342a01a4fd2efc788 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Wed, 22 Apr 2020 19:07:33 +0900
Subject: Made parentheses mandatory in endless method defition

Even for empty argument list, not to be confusing with a writer
method name.

diff --git a/parse.y b/parse.y
index 18f776e..09ba462 100644
--- a/parse.y
+++ b/parse.y
@@ -1114,7 +1114,7 @@ static int looking_at_eol_p(struct parser_params *p); https://github.com/ruby/ruby/blob/trunk/parse.y#L1114
 %type <node> command_rhs arg_rhs
 %type <node> command_asgn mrhs mrhs_arg superclass block_call block_command
 %type <node> f_block_optarg f_block_opt
-%type <node> f_arglist f_arglist_opt f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs f_rest_marg
+%type <node> f_arglist f_paren_args f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs f_rest_marg
 %type <node> assoc_list assocs assoc undef_list backref string_dvar for_var
 %type <node> block_param opt_block_param block_param_def f_opt
 %type <node> f_kwarg f_kw f_block_kwarg f_block_kw
@@ -2445,7 +2445,7 @@ arg		: lhs '=' arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L2445
 		    /*% %*/
 		    /*% ripper: ifop!($1, $3, $6) %*/
 		    }
-		| defn_head f_arglist_opt '=' arg
+		| defn_head f_paren_args '=' arg
 		    {
 			restore_defun(p, $<node>1->nd_defn);
 		    /*%%%*/
@@ -2454,7 +2454,7 @@ arg		: lhs '=' arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L2454
 		    /*% ripper: def!(get_value($1), $2, $4) %*/
 			local_pop(p);
 		    }
-		| defs_head f_arglist_opt '=' arg
+		| defs_head f_paren_args '=' arg
 		    {
 			restore_defun(p, $<node>1->nd_defn);
 		    /*%%%*/
@@ -4888,18 +4888,7 @@ superclass	: '<' https://github.com/ruby/ruby/blob/trunk/parse.y#L4888
 		    }
 		;
 
-f_arglist_opt	: f_arglist
-		| /* none */
-		    {
-		    /*%%%*/
-			$$ = new_args_tail(p, Qnone, Qnone, Qnone, &@0);
-			$$ = new_args(p, Qnone, Qnone, Qnone, Qnone, $$, &@0);
-		    /*% %*/
-		    /*% ripper: Qnil %*/
-		    }
-		;
-
-f_arglist	: '(' f_args rparen
+f_paren_args	: '(' f_args rparen
 		    {
 		    /*%%%*/
 			$$ = $2;
@@ -4923,6 +4912,9 @@ f_arglist	: '(' f_args rparen https://github.com/ruby/ruby/blob/trunk/parse.y#L4912
 			SET_LEX_STATE(EXPR_BEG);
 			p->command_start = TRUE;
 		    }
+                ;
+
+f_arglist       : f_paren_args
 		|   {
 			$<ctxt>$ = p->ctxt;
 			p->ctxt.in_kwarg = 1;
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index c471006..df6c2e3 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -1415,9 +1415,11 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L1415
   end
 
   def test_methoddef_endless
-    assert_valid_syntax('private def foo = 42')
+    assert_syntax_error('private def foo = 42', /unexpected '='/)
+    assert_valid_syntax('private def foo() = 42')
     assert_valid_syntax('private def inc(x) = x + 1')
-    assert_valid_syntax('private def obj.foo = 42')
+    assert_syntax_error('private def obj.foo = 42', /unexpected '='/)
+    assert_valid_syntax('private def obj.foo() = 42')
     assert_valid_syntax('private def obj.inc(x) = x + 1')
     eval('def self.inc(x) = x + 1 => @x')
     assert_equal(:inc, @x)
-- 
cgit v0.10.2


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

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