ruby-changes:62773
From: Yusuke <ko1@a...>
Date: Mon, 31 Aug 2020 20:30:44 +0900 (JST)
Subject: [ruby-changes:62773] 53ba9fb74e (master): Prohibit setter method names in endless method definition
https://git.ruby-lang.org/ruby.git/commit/?id=53ba9fb74e From 53ba9fb74ec57c18c3589e2e51f84a36467e3d9e Mon Sep 17 00:00:00 2001 From: Yusuke Endoh <mame@r...> Date: Mon, 31 Aug 2020 16:49:16 +0900 Subject: Prohibit setter method names in endless method definition https://bugs.ruby-lang.org/issues/16746#note-26 diff --git a/parse.y b/parse.y index 4efbd8c..83e6d20 100644 --- a/parse.y +++ b/parse.y @@ -2474,6 +2474,9 @@ arg : lhs '=' arg_rhs https://github.com/ruby/ruby/blob/trunk/parse.y#L2474 } | defn_head f_paren_args '=' arg { + if (is_attrset_id($<node>1->nd_mid)) { + yyerror1(&@1, "setter method cannot be defined in an endless method definition"); + } token_info_drop(p, "def", @1.beg_pos); restore_defun(p, $<node>1->nd_defn); /*%%%*/ diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 546b5a2..fb982e8 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1429,6 +1429,7 @@ eom https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L1429 end assert_equal("class ok", k.rescued("ok")) assert_equal("instance ok", k.new.rescued("ok")) + assert_syntax_error('def foo=() = 42', /setter method cannot be defined in an endless method definition/) end def test_methoddef_in_cond -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/