summaryrefslogtreecommitdiff
path: root/test/ruby/test_proc.rb
AgeCommit message (Collapse)Author
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
2019-12-23Reword keyword arguments warning messages to convey these are deprecation ↵Marc-Andre Lafortune
warnings
2019-12-20vm_args.c: rephrase the warning message of keyword argument separationYusuke Endoh
(old) test.rb:4: warning: The last argument is used as the keyword parameter test.rb:1: warning: for `foo' defined here; maybe ** should be added to the call? (new) test.rb:4: warning: The last argument is used as keyword parameters; maybe ** should be added to the call test.rb:1: warning: The called method `foo' is defined here
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-18Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans
This removes the security features added by $SAFE = 1, and warns for access or modification of $SAFE from Ruby-level, as well as warning when calling all public C functions related to $SAFE. This modifies some internal functions that took a safe level argument to no longer take the argument. rb_require_safe now warns, rb_require_string has been added as a version that takes a VALUE and does not warn. One public C function that still takes a safe level argument and that this doesn't warn for is rb_eval_cmd. We may want to consider adding an alternative method that does not take a safe level argument, and warn for rb_eval_cmd. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-14test/ruby/test_proc.rb: suppress "method redefined" warningsYusuke Endoh
2019-11-12Show the name `Kernel#proc` in the warning messageNobuyoshi Nakada
2019-09-26Fix more keyword separation issuesJeremy Evans
This fixes instance_exec and similar methods. It also fixes Enumerator::Yielder#yield, rb_yield_block, and a couple of cases with Proc#{<<,>>}. This support requires the addition of rb_yield_values_kw, similar to rb_yield_values2, for passing the keyword flag. Unlike earlier attempts at this, this does not modify the rb_block_call_func type or add a separate function type. The functions of type rb_block_call_func are called by Ruby with a separate VM frame, and we can get the keyword flag information from the VM frame flags, so it doesn't need to be passed as a function argument. These changes require the following VM functions accept a keyword flag: * vm_yield_with_cref * vm_yield * vm_yield_with_block Notes: Merged: https://github.com/ruby/ruby/pull/2493
2019-09-26Fix keyword argument separation issues in Proc#{<<,>>}Jeremy Evans
This requires adding rb_proc_call_with_block_kw. Notes: Merged: https://github.com/ruby/ruby/pull/2484
2019-08-14change Proc#to_s format ('@...' -> ' ...') (#2362)Koichi Sasada
Now Proc#to_s returns "#<Proc:0x00000237a0f5f170@t.rb:1>". However, it is convenient to select a file name by (double-)clicking on some terminals by separating ' ' instead of '@' like "#<Proc:0x00000237a0f5f170 t.rb:1>" [Feature #16101]
2019-07-15add tests for orphan/not-orphan proc/lambda.Tanaka Akira
2019-06-30Suppress unused variable warningsNobuyoshi Nakada
2019-04-26Hide internal IDsNobuyoshi Nakada
* parse.y (internal_id): number the ID serial for internal use by counting down from the neary maximum value, not to accidentally match permanent IDs. [Bug #15768] Notes: Fixed: [Bug #15786]
2019-01-10proc.c: proc without blocknobu
* proc.c (proc_new): promoted lambda/proc/Proc.new with no block in a method called with a block to a warning/error. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-10proc.c: check if callablenobu
* proc.c: check the argument at composition, expect a Proc, Method, or callable object. [ruby-core:90591] [Bug #15428] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66769 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22Proc#<< and Proc#>>nobu
[Feature #6284] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22proc.c: Support any callable when composing Procsnobu
* proc.c (proc_compose): support any object with a call method rather than supporting only procs. [Feature #6284] * proc.c (compose): use the function call on the given object rather than rb_proc_call_with_block in order to support any object. * test/ruby/test_proc.rb: Add test cases for composing Procs with callable objects. * test/ruby/test_method.rb: Add test cases for composing Methods with callable objects. From: Paul Mucur <paul@altmetric.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-22proc.c: Implement Proc#* for Proc compositionnobu
* proc.c (proc_compose): Implement Proc#* for Proc composition, enabling composition of Procs and Methods. [Feature #6284] * test/ruby/test_proc.rb: Add test cases for Proc composition. From: Paul Mucur <mudge@mudge.name> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-23remove VM_ENV_DATA_INDEX_ENV_PROC.ko1
* vm_core.h (VM_ENV_DATA_INDEX_ENV_PROC): ep[VM_ENV_DATA_INDEX_ENV_PROC] is allocated to mark a Proc which is created from iseq block. However, `lep[0]` keeps Proc object itself as a block handler (Proc). So we don't need to keep it. * vm_core.h (VM_ENV_PROCVAL): ditto. * vm.c (vm_make_env_each): do not need to keep blockprocval as special value. * vm.c (vm_block_handler_escape): simply return Proc value. * proc.c (proc_new): we don't need to check Env because a Proc type block handler is a Proc object itself. [Bug #14782] * test/ruby/test_proc.rb: add a test for [Bug #14782] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63494 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-18extend timeout morenaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61902 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-17extend timeoutnaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-08vm.c: respect redefinition of Proc#callnobu
* vm.c (vm_redefinition_check_method_type): hoist out method definition type to check redefinition. * vm.c (rb_vm_check_redefinition_opt_method): should check optimized method too. * vm.c (vm_init_redefined_flag): check Proc#call. * vm_insnhelper.c (vm_call_opt_block_call): search proper method if redefined. [Bug #14335] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61680 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-05extend timeout to 15 seconds for ARMv8 environmentnaruse
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-28`$SAFE` as a process global state. [Feature #14250]ko1
* vm_core.h (rb_vm_t): move `rb_execution_context_t::safe_level` to `rb_vm_t::safe_level_` because `$SAFE` is a process (VM) global state. * vm_core.h (rb_proc_t): remove `rb_proc_t::safe_level` because `Proc` objects don't need to keep `$SAFE` at the creation. Also make `is_from_method` and `is_lambda` as 1 bit fields. * cont.c (cont_restore_thread): no need to keep `$SAFE` for Continuation. * eval.c (ruby_cleanup): use `rb_set_safe_level_force()` instead of access `vm->safe_level_` directly. * eval_jump.c: End procs `END{}` doesn't keep `$SAFE`. * proc.c (proc_dup): removed and introduce `rb_proc_dup` in vm.c. * safe.c (rb_set_safe_level): don't check `$SAFE` 1 -> 0 changes. * safe.c (safe_setter): use `rb_set_safe_level()`. * thread.c (rb_thread_safe_level): `Thread#safe_level` returns `$SAFE`. It should be obsolete. * transcode.c (load_transcoder_entry): `rb_safe_level()` only returns 0 or 1 so that this check is not needed. * vm.c (vm_proc_create_from_captured): don't need to keep `$SAFE` for Proc. * vm.c (rb_proc_create): renamed to `proc_create`. * vm.c (rb_proc_dup): moved from proc.c. * vm.c (vm_invoke_proc): do not need to set and restore `$SAFE` for `Proc#call`. * vm_eval.c (rb_eval_cmd): rename a local variable to represent clearer meaning. * lib/drb/drb.rb: restore `$SAFE`. * lib/erb.rb: restore `$SAFE`, too. * test/lib/leakchecker.rb: check `$SAFE == 0` at the end of tests. * test/rubygems/test_gem.rb: do not set `$SAFE = 1`. * bootstraptest/test_proc.rb: catch up this change. * spec/ruby/optional/capi/string_spec.rb: ditto. * test/bigdecimal/test_bigdecimal.rb: ditto. * test/fiddle/test_func.rb: ditto. * test/fiddle/test_handle.rb: ditto. * test/net/imap/test_imap_response_parser.rb: ditto. * test/pathname/test_pathname.rb: ditto. * test/readline/test_readline.rb: ditto. * test/ruby/test_file.rb: ditto. * test/ruby/test_optimization.rb: ditto. * test/ruby/test_proc.rb: ditto. * test/ruby/test_require.rb: ditto. * test/ruby/test_thread.rb: ditto. * test/rubygems/test_gem_specification.rb: ditto. * test/test_tempfile.rb: ditto. * test/test_tmpdir.rb: ditto. * test/win32ole/test_win32ole.rb: ditto. * test/win32ole/test_win32ole_event.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-26test_proc.rb: remove duplicate test_source_locationnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e