summaryrefslogtreecommitdiff
path: root/test/ruby/test_method.rb
AgeCommit message (Collapse)Author
2024-04-17relax unused block warning for duck typingKoichi Sasada
if a method `foo` uses a block, other (unrelated) method `foo` can receives a block. So try to relax the unused block warning condition. ```ruby class C0 def f = yield end class C1 < C0 def f = nil end [C0, C1].f{ block } # do not warn ```
2024-04-15`super{}` doesn't use blockKoichi Sasada
`super(){}`, `super{}` and `super(&b)` doesn't use the given block so warn unused block warning when calling a method which doesn't use block with above `super` expressions. e.g.: `def f = super{B1}` (warn on `f{B2}` because `B2` is not used.
2024-04-15fix incorrect warning.Koichi Sasada
`super()` (not zsuper) passes the passed block and it can be used. ```ruby class C0 def foo; yield; end end class C1 < C0 def foo; super(); end end C1.new.foo{p :block} #=> :block ```
2024-04-15show warning for unused blockKoichi Sasada
With verbopse mode (-w), the interpreter shows a warning if a block is passed to a method which does not use the given block. Warning on: * the invoked method is written in C * the invoked method is not `initialize` * not invoked with `super` * the first time on the call-site with the invoked method (`obj.foo{}` will be warned once if `foo` is same method) [Feature #15554] `Primitive.attr! :use_block` is introduced to declare that primitive functions (written in C) will use passed block. For minitest, test needs some tweak, so use https://github.com/minitest/minitest/commit/ea9caafc0754b1d6236a490d59e624b53209734a for `test-bundled-gems`.
2024-02-22Skip under_gc_compact_stress on s390x (#10073)Takashi Kokubun
2024-02-20Add memory leak test for eval kwargsJohn Hawthorn
2024-02-15Do not include a backtick in error messages and backtracesYusuke Endoh
[Feature #16495]
2023-12-24Don't copy RUBY_FL_PROMOTED flag in rb_obj_setupPeter Zhu
RUBY_FL_PROMOTED is used by the garbage collector to track when an object becomes promoted to the old generation. rb_obj_setup must not copy that flag over because then it may become out-of-sync with the age of the object. This fixes a bug in Method#clone where the cloned Method object may get RUBY_FL_PROMOTED incorrectly set.
2023-08-03Remove --disable-gems for assert_separatelyPeter Zhu
assert_separately adds --disable=gems so we don't need to add --disable-gems when calling assert_separately. Notes: Merged: https://github.com/ruby/ruby/pull/8162
2023-07-24Use the caller location as default filename for eval family of methodsJean Boussier
[Feature #19755] Before (in /tmp/test.rb): ```ruby Object.class_eval("p __FILE__") # => "(eval)" ``` After: ```ruby Object.class_eval("p __FILE__") # => "(eval at /tmp/test.rb:1)" ``` This makes it much easier to track down generated code in case the author forgot to provide a filename argument. Notes: Merged: https://github.com/ruby/ruby/pull/8070
2023-04-30Handle private AREF call in compile.cNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/7775
2022-12-03UnboundMethod only refer defined_classKoichi Sasada
UnboundMethod records caller's class, like `D` or `E` on the following case: ```ruby class C def foo = :foo end class D < C end class E < C end d = D.instance_method(:foo) e = E.instance_method(:foo) ``` But `d` and `e` only refers `C#foo` so that UnboundMethod doesn't record `D` or `E`. This behavior changes the following methods: * `UnboundMethod#inspect` (doesn't show caller's class) * `UnboundMethod#==` (`d == e` for example) fix https://bugs.ruby-lang.org/issues/18798 Notes: Merged: https://github.com/ruby/ruby/pull/6855
2022-10-12Suppress a "warning: method redefined" in test/ruby/test_method.rbYusuke Endoh
2022-09-29Reduce diff to proc.c @ b0b9f7201acab05c2a3ad92c3043a1f01df3e17fBenoit Daloze
* So it's easy to review https://github.com/ruby/ruby/pull/6242 + https://github.com/ruby/ruby/pull/6467 and there are less changes overall.
2022-09-29Extend tests for a zsuper method of which the method it resolved to has been ↵Benoit Daloze
removed Notes: Merged: https://github.com/ruby/ruby/pull/6467
2022-09-29Resolve zsuper method during lookup but preserve owner separatelyBenoit Daloze
* See https://bugs.ruby-lang.org/issues/18729#note-34 * See [Bug #18729] Notes: Merged: https://github.com/ruby/ruby/pull/6467
2022-08-20Consider resolved-through-zsuper methods equal for compatibilityBenoit Daloze
* Fixes https://bugs.ruby-lang.org/issues/18751 Notes: Merged: https://github.com/ruby/ruby/pull/6242
2022-08-20Make Object#method and Module#instance_method not skip ZSUPER methodsJeremy Evans
Based on https://github.com/jeremyevans/ruby/commit/c95e7e5329140f640b6497905485761f3336d967 Among other things, this fixes calling visibility methods (public?, protected?, and private?) on them. It also fixes #owner to show the class the zsuper method entry is defined in, instead of the original class it references. For some backwards compatibility, adjust #parameters and #source_location, to show the parameters and source location of the method originally defined. Also have the parameters and source location still be shown by #inspect. Clarify documentation of {Method,UnboundMethod}#owner. Add tests based on the description of https://bugs.ruby-lang.org/issues/18435 and based on https://github.com/ruby/ruby/pull/5356#issuecomment-1005298809 Fixes [Bug #18435] [Bug #18729] Co-authored-by: Benoit Daloze <eregontp@gmail.com> Notes: Merged: https://github.com/ruby/ruby/pull/6242
2022-08-10Revert "Add {Method,UnboundMethod}#{public?,private?,protected?}"Jeremy Evans
This reverts commit 27278150685e738f84105d09843d3ba371146c7a and 58dc8bf8f15df9a33d191074e8a5d4946a3d59d5. Visibility is an attribute of the method entry in a class, not an attribute of the Method object. Fixes [#18729] Fixes [#18751] Fixes [#18435] Notes: Merged: https://github.com/ruby/ruby/pull/5974
2022-03-29Make define_singleton_method always define a public methodJeremy Evans
In very unlikely cases, it could previously define a non-public method starting in Ruby 2.1. Fixes [Bug #18561] Notes: Merged: https://github.com/ruby/ruby/pull/5636
2022-01-14Fix {Method,UnboundMethod}#{public?,private?,protected?} for ZSUPER methodsJeremy Evans
Add a visibility member to struct METHOD storing the original method visibility, and use that, instead of taking the visibility from the stored method entry (which may have different visibility for ZSUPER methods). Consider Method/UnboundMethod objects different if they have different visibilities. Fixes [Bug #18435] Notes: Merged: https://github.com/ruby/ruby/pull/5356
2022-01-04Fix the previous commitYusuke Endoh
2022-01-04test/ruby/test_method.rb: Fix a random failure during `make COVERAGE=1`Yusuke Endoh
This fixes the following failure. ``` 1) Error: TestMethod#test_method_list: NoMethodError: undefined method `<=>' for #<BasicObject:0x00007f7757e7eb60> mods = mods.sort_by {|m| m.name } ^^^^^^^^ ``` https://github.com/ruby/actions/runs/4699487470?check_suite_focus=true TestNoMethodError#test_to_s creates an anonymous module whose `#name` method returns a BasicObject. https://github.com/ruby/ruby/blob/f0669fb6cbdbad499974252ef2d955a608d0adc1/test/ruby/test_nomethod_error.rb#L95-L99 TestMethod#test_method_list uses `ObjectSpace.each_object(Module)` to gather all Modules and attempts to sort them by `#name`. But the anonymous module returns a BasicObject, which leads to the test failure above.
2022-01-04Use omit instead of skip: test/ruby/**/*.rbHiroshi SHIBATA
2021-12-30Add support for anonymous rest and keyword rest argument forwardingJeremy Evans
This allows for the following syntax: ```ruby def foo(*) bar(*) end def baz(**) quux(**) end ``` This is a natural addition after the introduction of anonymous block forwarding. Anonymous rest and keyword rest arguments were already supported in method parameters, this just allows them to be used as arguments to other methods. The same advantages of anonymous block forwarding apply to rest and keyword rest argument forwarding. This has some minor changes to #parameters output. Now, instead of `[:rest], [:keyrest]`, you get `[:rest, :*], [:keyrest, :**]`. These were already used for `...` forwarding, so I think it makes it more consistent to include them in other cases. If we want to use `[:rest], [:keyrest]` in both cases, that is also possible. I don't think the previous behavior of `[:rest], [:keyrest]` in the non-... case and `[:rest, :*], [:keyrest, :**]` in the ... case makes sense, but if we did want that behavior, we'll have to make more substantial changes, such as using a different ID in the ... forwarding case. Implements [Feature #18351] Notes: Merged: https://github.com/ruby/ruby/pull/5148
2021-12-09Add {Method,UnboundMethod}#{public?,private?,protected?}Jeremy Evans
These methods allow for checking whether the method has that visibility. Implements [Feature #11689] Notes: Merged: https://github.com/ruby/ruby/pull/5040
2021-08-03Add keyrest to ruby2_keywords parameters [Bug #18011]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4705
2021-07-29use me->def instead of me for opt_tableKoichi Sasada
`vm_opt_method_table` is me=>bop table to manage the optimized methods (by specialized instruction). However, `me` can be invalidated to invalidate the method cache entry. [Bug #17725] To solve the issue, use `me-def` instead of `me` which simply copied at invalidation timing. A test by @jeremyevans https://github.com/ruby/ruby/pull/4376 Notes: Merged: https://github.com/ruby/ruby/pull/4493
2021-04-07[Bug #17780] Fix Method#super_method for module aliasPeter Zhu
Method#super_method crashes for aliased module methods because they are not defined on a class. This bug was introduced in c60aaed1856b2b6f90de0992c34771830019e021 as part of bug #17130. Notes: Merged: https://github.com/ruby/ruby/pull/4364
2020-12-24Remove unneeded codeMarc-Andre Lafortune
Notes: Merged: https://github.com/ruby/ruby/pull/3993
2020-12-23Fix class of method in Method#inspect for singleton classes of classesJeremy Evans
Previously, due to a change to fix bug 15608, Method#inspect output changed for class methods: Ruby 2.7 "#<Method: String.prepend(*)>" Before change: "#<Method: #<Class:Object>(Module)#prepend(*)>" This is wrong because the Method object was created from String and not Object. This is because the fix for bug 15608 assumed it was being called on the singleton class of a instance, and would skip the first singleton class until it got to the class itself. For class methods, this results in always using the superclass. Fix behavior to not skip until the superclass if the singleton class is the singleton class of a module or class. After change: "#<Method: #<Class:Object>(Module)#prepend(*)>" Fixes [Bug #17428] Notes: Merged: https://github.com/ruby/ruby/pull/3984
2020-12-17test/ruby: Check warning messages at a finer granularityNobuyoshi Nakada
Instead of suppressing all warnings wholly in each test scripts by setting `$VERBOSE` to `nil` in `setup` methods. Notes: Merged: https://github.com/ruby/ruby/pull/3925 Merged-By: nobu <nobu@ruby-lang.org>
2020-10-03Fix assert_ruby_status usage in 174ae0f5775cc7af7d197963a8f87b7d1972c268Kazuhiro NISHIYAMA
2020-10-03Remove known use-after-poison bugNobuyoshi Nakada
9eda6547812cbda23a73ba3b2620520b0de2bdd6 was fixed by b9488accf9e2cbf5f7c47b42b3eb23469f0aa58d.
2020-08-27Fix Method#super_method for aliased methodsJeremy Evans
Previously, Method#super_method looked at the called_id to determine the method id to use, but that isn't correct for aliased methods, because the super target depends on the original method id, not the called_id. Additionally, aliases can reference methods defined in other classes and modules, and super lookup needs to start in the super of the defined class in such cases. This adds tests for Method#super_method for both types of aliases, one that uses VM_METHOD_TYPE_ALIAS and another that does not. Both check that the results for calling super methods return the expected values. To find the defined class for alias methods, add an rb_ prefix to find_defined_class_by_owner in vm_insnhelper.c and make it non-static, so that it can be called from method_super_method in proc.c. This bug was original discovered while researching [Bug #11189]. Fixes [Bug #17130] Notes: Merged: https://github.com/ruby/ruby/pull/3458 Merged-By: jeremyevans <code@jeremyevans.net>
2020-06-09Work around infinite loop when overriding method visibility in prepended ↵Jeremy Evans
module (#3201) For ZSUPER methods with no defined class for the method entry, start the next lookup at the superclass of the origin class of the method owner, instead of the superclass of the method owner. Fixes [Bug #16942] Notes: Merged-By: jeremyevans <code@jeremyevans.net>
2020-03-22Merge pull request #2721 from jeremyevans/method-inspect-chain-alias-11188Jeremy Evans
Correctly show defined class for aliases of aliases Notes: Merged-By: jeremyevans <code@jeremyevans.net>
2020-03-09Don't display singleton class in Method#inspect unless method defined thereJeremy Evans
Previously, if an object has a singleton class, and you call Object#method on the object, the resulting string would include the object's singleton class, even though the method was not defined in the singleton class. Change this so the we only show the singleton class if the method is defined in the singleton class. Fixes [Bug #15608] Notes: Merged: https://github.com/ruby/ruby/pull/2949 Merged-By: jeremyevans <code@jeremyevans.net>
2020-01-29refactoring: use Proc and Constant.Koichi Sasada
2020-01-28support multi-run for test/ruby/test_method.rbKoichi Sasada
need to restore a method.
2020-01-09Fixed up 0eeed5bcc5530edb0af2af2ccff09d067c59e8f9Nobuyoshi Nakada
`Binding#source_location` returns the `__FILE__` when created, and may not be an absolute or real path. And in the `eval` context with an explicit file name, `__dir__` also returns that name. On the other hand, `__FILE__` in `require`d script file has been expanded at searching the library.
2020-01-03Make eval(code, binding) use (eval) as __FILE__ and 1 as __LINE__Jeremy Evans
This removes the warning that was added in 3802fb92ff8c83eed3e867db20f72c53932f542d, and switches the behavior so that the eval does not use the binding's __FILE__ and __LINE__ implicitly. Fixes [Bug #4352] Notes: Merged: https://github.com/ruby/ruby/pull/2816
2019-12-04Make {Method,UnboundMethod}#super_method handle clone/bind/unbindJeremy Evans
This wasn't working previously because the iclass entry wasn't being copied, and without an iclass entry, super_method returns nil. Fixes [Bug #15629] Notes: Merged: https://github.com/ruby/ruby/pull/2723
2019-11-21Refined inspection of argument forwardingNobuyoshi Nakada
2019-11-20Add tests of argument forwarding's parameters and inspectKazuhiro NISHIYAMA
2019-11-20Update representation (discussed on ruby tracker)zverok
Notes: Merged: https://github.com/ruby/ruby/pull/2618
2019-11-20Method parameters inspectzverok
Example: def m(a, b=nil, *c, d:, e: nil, **rest, &block) end p method(:m) #=> #<Method: m(a, b=<default>, *c, d:, e: <default>, **rest, &block) ...> Notes: Merged: https://github.com/ruby/ruby/pull/2618
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-12Revert "Method reference operator"Nobuyoshi Nakada
This reverts commit 67c574736912003c377218153f9d3b9c0c96a17b. [Feature #16275]
2019-10-01remove `unused var` warningKoichi Sasada