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]
This commit is contained in:
Yusuke Endoh 2019-09-13 17:02:08 +09:00
parent 3a87826d0c
commit 191ce5344e
Notes: git 2019-11-29 17:32:53 +09:00
4 changed files with 204 additions and 42 deletions

View file

@ -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)}