ruby-changes:44558
From: nobu <ko1@a...>
Date: Sun, 6 Nov 2016 14:42:57 +0900 (JST)
Subject: [ruby-changes:44558] nobu:r56631 (trunk): include and prepend check no args
nobu 2016-11-06 14:42:53 +0900 (Sun, 06 Nov 2016) New Revision: 56631 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56631 Log: include and prepend check no args * eval.c (rb_mod_include, rb_mod_prepend): check if arguments are given, as well as Kernel#extend. [ruby-dev:49854] [Bug #12887] [Fix GH-1470] Modified files: trunk/ChangeLog trunk/eval.c trunk/test/ruby/test_module.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 56630) +++ ChangeLog (revision 56631) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun Nov 6 14:42:50 2016 takkanm <takkanm@g...> + + * eval.c (rb_mod_include, rb_mod_prepend): check if arguments are + given, as well as Kernel#extend. [ruby-dev:49854] [Bug #12887] + [Fix GH-1470] + Sun Nov 6 11:59:05 2016 Shugo Maeda <shugo@r...> * test/rinda/test_rinda.rb (test_make_socket_ipv6_multicast, Index: eval.c =================================================================== --- eval.c (revision 56630) +++ eval.c (revision 56631) @@ -1036,6 +1036,7 @@ rb_mod_include(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/eval.c#L1036 CONST_ID(id_append_features, "append_features"); CONST_ID(id_included, "included"); + rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS); for (i = 0; i < argc; i++) Check_Type(argv[i], T_MODULE); while (argc--) { @@ -1083,6 +1084,8 @@ rb_mod_prepend(int argc, VALUE *argv, VA https://github.com/ruby/ruby/blob/trunk/eval.c#L1084 CONST_ID(id_prepend_features, "prepend_features"); CONST_ID(id_prepended, "prepended"); + + rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS); for (i = 0; i < argc; i++) Check_Type(argv[i], T_MODULE); while (argc--) { Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 56630) +++ test/ruby/test_module.rb (revision 56631) @@ -440,6 +440,10 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L440 EOS end + def test_include_with_no_args + assert_raise(ArgumentError) { Module.new { include } } + end + def test_included_modules assert_equal([], Mixin.included_modules) assert_equal([Mixin], User.included_modules) @@ -1868,6 +1872,10 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1872 end; end + def test_prepend_module_with_no_args + assert_raise(ArgumentError) { Module.new { prepend } } + end + def test_class_variables m = Module.new m.class_variable_set(:@@foo, 1) @@ -1934,6 +1942,10 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1942 assert_equal(['public', 'protected'], list) end + def test_extend_module_with_no_args + assert_raise(ArgumentError) { Module.new { extend } } + end + def test_invalid_attr %W[ foo? -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/