1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-02-26 01:24:52 +00:00
parent 47809f0934
commit c07d78eb0e
3 changed files with 23 additions and 1 deletions

View file

@ -1,3 +1,9 @@
Tue Feb 26 10:24:49 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@zacharyscott.net> Tue Feb 26 04:50:00 2013 Zachary Scott <zachary@zacharyscott.net>
* error.c: clarify reason for sleep in SignalException example * error.c: clarify reason for sleep in SignalException example

View file

@ -6760,7 +6760,7 @@ parser_prepare(struct parser_params *parser)
#define IS_END() IS_lex_state(EXPR_END_ANY) #define IS_END() IS_lex_state(EXPR_END_ANY)
#define IS_BEG() IS_lex_state(EXPR_BEG_ANY) #define IS_BEG() IS_lex_state(EXPR_BEG_ANY)
#define IS_SPCARG(c) (IS_ARG() && space_seen && !ISSPACE(c)) #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_LABEL_SUFFIX(n) (peek_n(':',(n)) && !peek_n(':', (n)+1))
#define IS_AFTER_OPERATOR() IS_lex_state(EXPR_FNAME | EXPR_DOT) #define IS_AFTER_OPERATOR() IS_lex_state(EXPR_FNAME | EXPR_DOT)

View file

@ -274,4 +274,20 @@ class TestKeywordArguments < Test::Unit::TestCase
assert_valid_syntax("def bug7662(*, **) end") assert_valid_syntax("def bug7662(*, **) end")
assert_valid_syntax("def bug7662(a, **) end") assert_valid_syntax("def bug7662(a, **) end")
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 end