aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_struct.rb
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2019-09-13 17:02:08 +0900
committerYusuke Endoh <mame@ruby-lang.org>2019-11-29 17:32:27 +0900
commit191ce5344ec42c91571f8f47c85be9138262b1c7 (patch)
tree5f9f222cc5bfe870208673ceb3eba95c7a823239 /test/ruby/test_struct.rb
parent3a87826d0c3dd4c42e327e0cd4fb0806d898497f (diff)
downloadruby-191ce5344ec42c91571f8f47c85be9138262b1c7.tar.gz
Reduce duplicated warnings for the change of Ruby 3 keyword arguments
By this change, the following code prints only one warning. ``` def foo(**opt); end 100.times { foo({kw:1}) } ``` A global variable `st_table *caller_to_callees` is a map from caller to a set of callee methods. It remembers that a warning is already printed for each pair of caller and callee. [Feature #16289]
Diffstat (limited to 'test/ruby/test_struct.rb')
-rw-r--r--test/ruby/test_struct.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb
index 2f5ef80c9b..884fbe00ed 100644
--- a/test/ruby/test_struct.rb
+++ b/test/ruby/test_struct.rb
@@ -113,7 +113,8 @@ module TestStruct
assert_equal @Struct::KeywordInitTrue.new(a: 1, b: 2).values, @Struct::KeywordInitFalse.new(1, 2).values
assert_equal "#{@Struct}::KeywordInitFalse", @Struct::KeywordInitFalse.inspect
assert_equal "#{@Struct}::KeywordInitTrue(keyword_init: true)", @Struct::KeywordInitTrue.inspect
- k = Class.new(@Struct::KeywordInitFalse) {def initialize(**) end}
+ # eval is neede to prevent the warning duplication filter
+ k = eval("Class.new(@Struct::KeywordInitFalse) {def initialize(**) end}")
assert_warn(/The last argument is used as the keyword parameter/) {k.new(a: 1, b: 2)}
k = Class.new(@Struct::KeywordInitTrue) {def initialize(**) end}
assert_warn('') {k.new(a: 1, b: 2)}