summaryrefslogtreecommitdiff
path: root/test/ruby/test_proc.rb
AgeCommit message (Collapse)Author
2025-12-30Reapply "[Feature #6012] Extend `source_location` for end positionBenoit Daloze
* This reverts commit 065c48cdf11a1c4cece84db44ed8624d294f8fd5. * This functionality is very valuable and has already taken 14 years to agree on the API. * Let's just document it's byte columns (in the next commit). * See https://bugs.ruby-lang.org/issues/21783#note-9
2025-12-24Prevent "warning: assigned but unused variable - it"Yusuke Endoh
2025-12-16Revert "[Feature #6012] Extend `source_location` for end positionNobuyoshi Nakada
and columns" This reverts commit 073c4e1cc712064e626914fa4a5a8061f903a637. https://bugs.ruby-lang.org/issues/6012#note-31 > we will cancel this feature in 4.0 because of design ambiguities > such as whether to return column positions in bytes or characters as > in [#21783]. [#21783]: https://bugs.ruby-lang.org/issues/21783
2025-12-13Fix binding.implicit_parameters_get/defined segfault when wrong name string ↵tomoya ishida
is passed (#15530)
2025-12-12Binding#implicit_parameters, etc. support the implicit "it" parameterYusuke Endoh
[Bug #21049]
2025-12-12Add Binding#implicit_parameters, etc.Yusuke Endoh
This changeset introduces: * `Binding#implicit_parameters` * `Binding#implicit_parameter_get` * `Binding#implicit_parameter_defined?` [Bug #21049]
2025-12-12Binding#local_variable_defined? raises a NameError for numbered params.Yusuke Endoh
[Bug #21776]
2025-12-12`Binding#local_variable_defined?` must not handle numbered parametersYusuke Endoh
[Bug #21776]
2025-07-16Suppress warnings for variablesNobuyoshi Nakada
2025-05-21Fix one-by-one error of numbered parameter IDRichard Böhme
Notes: Merged: https://github.com/ruby/ruby/pull/13395
2025-02-18Add a test for Binding#local_variable* with numbered parameters and `it`Yusuke Endoh
Notes: Merged: https://github.com/ruby/ruby/pull/12746
2025-01-14Add tests for Proc#parameters on `it` blocksAlan Wu
[Bug #20955]
2025-01-13Proc#parameters: Show anonymous optionals as `[:opt]`Alan Wu
Have this for lead parameters as well as parameters after rest ("post"). [Bug #20974] Notes: Merged: https://github.com/ruby/ruby/pull/12547
2025-01-09[Feature #6012] Extend `source_location` for end position and columnsNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/12539
2024-12-13Fix use-after-free in ep in Proc#dup for ifunc procsPeter Zhu
[Bug #20950] ifunc proc has the ep allocated in the cfunc_proc_t which is the data of the TypedData object. If an ifunc proc is duplicated, the ep points to the ep of the source object. If the source object is freed, then the ep of the duplicated object now points to a freed memory region. If we try to use the ep we could crash. For example, the following script crashes: p = { a: 1 }.to_proc 100.times do p = p.dup GC.start p.call rescue ArgumentError end This commit changes ifunc proc to also duplicate the ep when it is duplicated. Notes: Merged: https://github.com/ruby/ruby/pull/12319
2024-11-02Skip TestProc#test_hash_does_not_change_after_compaction if compaction is ↵Peter Zhu
not supported Notes: Merged: https://github.com/ruby/ruby/pull/11980
2024-11-01Improve coverage of TestProc#test_hash_uniquenessPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11966
2024-11-01Add TestProc#test_hash_equalPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11966
2024-11-01Rename test_hash to test_hash_uniquenessPeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/11966
2024-11-01[Bug #20853] Fix Proc#hash to not change after compactionPeter Zhu
The hash value of a Proc must remain constant after a compaction, otherwise it may not work as the key in a hash table. Notes: Merged: https://github.com/ruby/ruby/pull/11966
2024-10-31Fix assertion when envval of proc is QundefPeter Zhu
The following code crashes with assertions enabled because envval could be Qundef: {}.to_proc.dup Notes: Merged: https://github.com/ruby/ruby/pull/11970
2024-10-31Fix indentation in TestProc#test_hash [ci skip]Peter Zhu
2024-09-15Prevent warnings: the block passed to ... may be ignoredYusuke Endoh
2024-09-13Prevent warnings "the block passed to ... may be ignored"Yusuke Endoh
Notes: Merged: https://github.com/ruby/ruby/pull/11611
2024-02-06[PRISM] Use block node location when building block iseqNikita Vasilevsky
Co-Authored-By: Kevin Newton <kddnewton@gmail.com>
2023-10-26[Feature #19362] Call `#initialize_dup` hook at `Proc#dup`Nobuyoshi Nakada
2023-09-12Make Kernel#lambda raise when given non-literal blockAlan Wu
Previously, Kernel#lambda returned a non-lambda proc when given a non-literal block and issued a warning under the `:deprecated` category. With this change, Kernel#lambda will always return a lambda proc, if it returns without raising. Due to interactions with block passing optimizations, we previously had two separate code paths for detecting whether Kernel#lambda got a literal block. This change allows us to remove one path, the hack done with rb_control_frame_t::block_code introduced in 85a337f for supporting situations where Kernel#lambda returned a non-lambda proc. [Feature #19777] Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com> Notes: Merged: https://github.com/ruby/ruby/pull/8405
2023-07-10Fix autosplat conditions to handle ruby2_keywords caseJeremy Evans
Autosplat should not occur if there are two arguments but second argument is an array containing a ruby2_keywords splat. Only autosplat if a single argument to be yielded to the block, and there is no splatted flagged keyword hash passed. Fixes [Bug #19759] Notes: Merged: https://github.com/ruby/ruby/pull/8039 Merged-By: jeremyevans <code@jeremyevans.net>
2022-04-06Raise RuntimeError if Kernel#binding is called from a non-Ruby frameJeremy Evans
Check whether the current or previous frame is a Ruby frame in call_trace_func and rb_tracearg_binding before attempting to create a binding for the frame. Fixes [Bug #18487] Co-authored-by: Alan Wu <XrXr@users.noreply.github.com> Notes: Merged: https://github.com/ruby/ruby/pull/5767 Merged-By: jeremyevans <code@jeremyevans.net>
2022-04-01Revert "Raise RuntimeError if Kernel#binding is called from a non-Ruby frame"Jeremy Evans
This reverts commit 343ea9967e4a6b279eed6bd8e81ad0bdc747f254. This causes an assertion failure with -DRUBY_DEBUG=1 -DRGENGC_CHECK_MODE=2
2022-03-30Do not autosplat array in block call just because keywords acceptedJeremy Evans
If the block only accepts a single positional argument plus keywords, then do not autosplat. Still autosplat if the block accepts more than one positional argument in addition to keywords. Autosplatting a single positional argument plus keywords made sense in Ruby 2, since a final positional hash could be used as keywords, but it does not make sense in Ruby 3. Fixes [Bug #18633] Notes: Merged: https://github.com/ruby/ruby/pull/5665 Merged-By: jeremyevans <code@jeremyevans.net>
2022-03-24Raise RuntimeError if Kernel#binding is called from a non-Ruby frameJeremy Evans
Check whether the current or previous frame is a Ruby frame in call_trace_func before attempting to create a binding for the frame. Fixes [Bug #18487] Co-authored-by: Alan Wu <XrXr@users.noreply.github.com> Notes: Merged: https://github.com/ruby/ruby/pull/5567
2022-03-17Make Proc#parameters support lambda keyword for returning parameters as if ↵Jeremy Evans
lambda This makes it easier to use Proc#parameters to build wrappers. Implements [Feature #15357] Notes: Merged: https://github.com/ruby/ruby/pull/5677
2022-01-13T#dup (T < Proc) should return T's objectKoichi Sasada
T#dup (T < Proc) returns Proc object (not T) from Ruby 1.9. [Bug #17545] Notes: Merged: https://github.com/ruby/ruby/pull/4197
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-10-29Preserve the encoding of message from outer local variablesNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/5053
2021-10-29Remove redundant callsNobuyoshi Nakada
The ArgumentError should raise in `isolate`. Notes: Merged: https://github.com/ruby/ruby/pull/5053
2021-06-24Remove shift of ep when computing Proc#hashJeremy Evans
The shift was causing far fewer unique values of hash than expected. Fix pointed out by xtkoba (Tee KOBAYASHI) Fixes [Bug #17951] Notes: Merged: https://github.com/ruby/ruby/pull/4574
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-12-12fix lambda's warning and testsKoichi Sasada
There are warning condition bugs and test bugs. b53ccb9c69abd24e3bdad66cbe4c7e7480eaef16
2020-12-11show deprecation warning correctly for lambda(&b)Koichi Sasada
lambda(&b) where b is given block of method (like: def foo(&b)) should warn correctly. [Feature #17361] Also labmda(&labmda_block) or lambda(&:to_s) (Symbol#to_proc) should not warn (but I'm not sure who cares about it).
2020-10-29check isolated Proc more strictlyKoichi Sasada
Isolated Proc prohibit to access outer local variables, but it was violated by binding and so on, so they should be error. Notes: Merged: https://github.com/ruby/ruby/pull/3721
2020-06-19Implement Proc#== and #eql?Jeremy Evans
Previously, these were not implemented, and Object#== and #eql? were used. This tries to check the proc internals to make sure that procs created from separate blocks are treated as not equal, but procs created from the same block are treated as equal, even when the lazy proc allocation optimization is used. Implements [Feature #14267] Notes: Merged: https://github.com/ruby/ruby/pull/3174
2020-06-10Make proc/Proc.new without block an error instead of warningJeremy Evans
The warning for these was added in 2.7. Notes: Merged: https://github.com/ruby/ruby/pull/3208
2020-03-08Do not autosplat when calling procs that accept rest and keywordsJeremy Evans
When providing a single array to a block that takes a splat, pass the array as one argument of the splat instead of as the splat itself, even if the block also accepts keyword arguments. Previously, this behavior was only used for blocks that did not accept keywords. Implements [Feature#16166] Notes: Merged: https://github.com/ruby/ruby/pull/2502
2020-01-28support multi-run for test/ruby/test_proc.rbKoichi Sasada
Mysterious error: `remove_method(:foo) if method_defined?(:foo)` raise an exception `method `foo' not defined in #<Class:#<TestProc:0x000055d12ff154e0>>` This patch rename the method name foo to foo_arity to solve it.
2020-01-24Do not autosplat when calling proc with empty keyword splatJeremy Evans
With the removal of the splatted argument when using an empty keyword splat, the autosplat code considered an empty keyword splat the same as no argument at all. However, that results in autosplat behavior changing dependent on the content of the splatted hash, which is not what anyone would expect or want. This change always skips an autosplat if keywords were provided. Fixes [Bug #16560] Notes: Merged: https://github.com/ruby/ruby/pull/2861
2020-01-02Update tests for full keyword argument separationJeremy Evans
Notes: Merged: https://github.com/ruby/ruby/pull/2794
2020-01-02Fully separate positional arguments and keyword argumentsJeremy Evans
This removes the warnings added in 2.7, and changes the behavior so that a final positional hash is not treated as keywords or vice-versa. To handle the arg_setup_block splat case correctly with keyword arguments, we need to check if we are taking a keyword hash. That case didn't have a test, but it affects real-world code, so add a test for it. This removes rb_empty_keyword_given_p() and related code, as that is not needed in Ruby 3. The empty keyword case is the same as the no keyword case in Ruby 3. This changes rb_scan_args to implement keyword argument separation for C functions when the : character is used. For backwards compatibility, it returns a duped hash. This is a bad idea for performance, but not duping the hash breaks at least Enumerator::ArithmeticSequence#inspect. Instead of having RB_PASS_CALLED_KEYWORDS be a number, simplify the code by just making it be rb_keyword_given_p(). Notes: Merged: https://github.com/ruby/ruby/pull/2794
2019-12-30Decide lambdaness of (f << g) using g (#2729)Alan Wu
* Deciding lambdaness of (f << g) using g * Use version guards for spec changes Notes: Merged-By: XrXr