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

ruby-changes:27452

From: nobu <ko1@a...>
Date: Tue, 26 Feb 2013 10:25:04 +0900 (JST)
Subject: [ruby-changes:27452] nobu:r39504 (trunk): parse.y: keyword argument without paren

nobu	2013-02-26 10:24:52 +0900 (Tue, 26 Feb 2013)

  New Revision: 39504

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39504

  Log:
    parse.y: keyword argument without paren
    
    * parse.y (IS_LABEL_POSSIBLE): allow labels for keyword arguments just
      after method definition without a parenthesis.  [ruby-core:52820]
      [Bug #7942]

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_keyword.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39503)
+++ ChangeLog	(revision 39504)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Feb 26 10:24:49 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (IS_LABEL_POSSIBLE): allow labels for keyword arguments just
+	  after method definition without a parenthesis.  [ruby-core:52820]
+	  [Bug #7942]
+
 Tue Feb 26 04:50:00 2013  Zachary Scott  <zachary@z...>
 
 	* error.c: clarify reason for sleep in SignalException example
Index: parse.y
===================================================================
--- parse.y	(revision 39503)
+++ parse.y	(revision 39504)
@@ -6760,7 +6760,7 @@ parser_prepare(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L6760
 #define IS_END() IS_lex_state(EXPR_END_ANY)
 #define IS_BEG() IS_lex_state(EXPR_BEG_ANY)
 #define IS_SPCARG(c) (IS_ARG() && space_seen && !ISSPACE(c))
-#define IS_LABEL_POSSIBLE() ((IS_lex_state(EXPR_BEG) && !cmd_state) || IS_ARG())
+#define IS_LABEL_POSSIBLE() ((IS_lex_state(EXPR_BEG | EXPR_ENDFN) && !cmd_state) || IS_ARG())
 #define IS_LABEL_SUFFIX(n) (peek_n(':',(n)) && !peek_n(':', (n)+1))
 #define IS_AFTER_OPERATOR() IS_lex_state(EXPR_FNAME | EXPR_DOT)
 
Index: test/ruby/test_keyword.rb
===================================================================
--- test/ruby/test_keyword.rb	(revision 39503)
+++ test/ruby/test_keyword.rb	(revision 39504)
@@ -274,4 +274,20 @@ class TestKeywordArguments < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_keyword.rb#L274
     assert_valid_syntax("def bug7662(*, **) end")
     assert_valid_syntax("def bug7662(a, **) end")
   end
+
+  def test_without_paren
+    bug7942 = '[ruby-core:52820] [Bug #7942]'
+    assert_valid_syntax("def bug7942 a: 1; end")
+    assert_valid_syntax("def bug7942 a: 1, **; end")
+
+    o = Object.new
+    eval("def o.bug7942 a: 1; a; end", nil, __FILE__, __LINE__)
+    assert_equal(1, o.bug7942(), bug7942)
+    assert_equal(42, o.bug7942(a: 42), bug7942)
+
+    o = Object.new
+    eval("def o.bug7942 a: 1, **; a; end", nil, __FILE__, __LINE__)
+    assert_equal(1, o.bug7942(), bug7942)
+    assert_equal(42, o.bug7942(a: 42), bug7942)
+  end
 end

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

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