summaryrefslogtreecommitdiff
path: root/test/ruby/test_module.rb
AgeCommit message (Collapse)Author
2024-02-15Do not include a backtick in error messages and backtracesYusuke Endoh
[Feature #16495]
2024-02-08Fix crash when checking symbol encodingPeter Zhu
[Bug #20245] We sometimes pass in a fake string to sym_check_asciionly. This can crash if sym_check_asciionly raises because it creates a CFP with the fake string as the receiver which will crash if GC tries to mark the CFP. For example, the following script crashes: GC.stress = true Object.const_defined?("\xC3")
2023-09-23[Bug #19901]Adam Hess
fix leak in module clone Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2023-09-22[Bug #19896]Adam Hess
fix memory leak in vm_method This introduces a unified reference_count to clarify who is referencing a method. This also allows us to treat the refinement method as the def owner since it counts itself as a reference Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2023-09-20Fix memory leak in complemented method entriesPeter Zhu
[Bug #19894] When a copy of a complemented method entry is created, there are two issues: 1. IMEMO_FL_USER3 is not copied, so the complemented status is not copied over. 2. In rb_method_entry_clone we increment both alias_count and complemented_count. However, when we free the method entry in rb_method_definition_release, we only decrement one of the two counters, resulting in the rb_method_definition_t being leaked. Co-authored-by: Adam Hess <adamhess1991@gmail.com>
2023-06-03Attrset name is not allowed as an attributeNobuyoshi Nakada
2023-03-28Fix memory leak for iclassPeter Zhu
[Bug #19550] If !RCLASS_EXT_EMBEDDED (e.g. 32 bit systems) then the rb_classext_t is allocated throug malloc so it must be freed. The issue can be seen in the following script: ``` 20.times do 100_000.times do mod = Module.new Class.new do include mod end end # Output the Resident Set Size (memory usage, in KB) of the current Ruby process puts `ps -o rss= -p #{$$}` end ``` Before this fix, the max RSS is 280MB, while after this change, it's 30MB. Notes: Merged: https://github.com/ruby/ruby/pull/7597
2023-03-17Fix small issues concerning namespacing in test-all suitelukeg
* Fix temporary methods on Object leaking across test cases. * Remove temporary classes/modules leaking across test cases. Notes: Merged: https://github.com/ruby/ruby/pull/7513
2023-03-06s/mjit/rjit/Takashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7462
2023-03-06s/MJIT/RJIT/Takashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7462
2023-02-20Update some tests for the new message format of NoMethodErrorYusuke Endoh
Notes: Merged: https://github.com/ruby/ruby/pull/6950
2022-12-01Module#remove_method: Check frozen on the right objectJean byroot Boussier
Previously, the frozen check happened on `RCLASS_ORIGIN(self)`, which can return an iclass. The frozen check is supposed to respond to objects that users can call methods on while iclasses are hidden from users. Other mutation methods like Module#{define_method,alias_method,public} don't do this. Check frozen status on the module itself. Fixes [Bug #19164] and [Bug #19166]. Co-authored-by: Alan Wu <XrXr@users.noreply.github.com> Notes: Merged: https://github.com/ruby/ruby/pull/6842 Merged-By: XrXr
2022-09-06Skip test_redefinition_mismatch on trunk-mjit for nowTakashi Kokubun
Investigating: http://ci.rvm.jp/logfiles/brlog.trunk-mjit.20220906-025646 which is not immediately reproducible on my laptop.
2022-07-21Do not have class/module keywords look up ancestors of ObjectJeremy Evans
Fixes case where Object includes a module that defines a constant, then using class/module keyword to define the same constant on Object itself. Implements [Feature #18832] Notes: Merged: https://github.com/ruby/ruby/pull/6048
2022-06-06Add Module#undefined_instance_methodsJeremy Evans
Implements [Feature #12655] Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/5733 Merged-By: jeremyevans <code@jeremyevans.net>
2022-04-16Fix class ancestry checks for duped classesJohn Hawthorn
Previously in some when classes were duped (specifically those with a prepended module), they would not correctly have their "superclasses" array or depth filled in. This could cause ancestry checks (like is_a? and Module comparisons) to return incorrect results. This happened because rb_mod_init_copy builds origin classes in an order that doesn't have the super linked list fully connected until it's finished. This commit fixes the previous issue by calling rb_class_update_superclasses before returning the cloned class. This is similar to what's already done in make_metaclass. Notes: Merged: https://github.com/ruby/ruby/pull/5808
2022-03-11Add test for protected methods on module includedJohn Hawthorn
Notes: Merged: https://github.com/ruby/ruby/pull/5642
2022-01-17Fix the placeholder subclass entry skipping [Bug #18489]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/5455
2022-01-14Add a Module#const_added callbackJean Boussier
[Feature #17881] Works similarly to `method_added` but for constants. ```ruby Foo::BAR = 42 # call Foo.const_added(:FOO) class Foo::Baz; end # call Foo.const_added(:Baz) Foo.autoload(:Something, "path") # call Foo.const_added(:Something) ``` Notes: Merged: https://github.com/ruby/ruby/pull/4521
2022-01-06Update test/ruby/test_module.rbJeremy Evans
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> Notes: Merged: https://github.com/ruby/ruby/pull/5398
2022-01-06Allow include before calling Module#initializeJeremy Evans
This is to allow Module subclasses that include modules before calling super in the subclass's initialize. Remove rb_module_check_initializable from Module#initialize. Module#initialize only calls module_exec if a block is passed, it doesn't have other issues that would cause problems if called multiple times or with an already initialized module. Move initialization of super to Module#allocate, though I'm not sure it is required there. However, it's needed to be removed from Module#initialize for this to work. Fixes [Bug #18292] Notes: Merged: https://github.com/ruby/ruby/pull/5398
2021-11-18Make Module#{public,private,protected,module_function} return argumentsJeremy Evans
Previously, each of these methods returned self, but it is more useful to return arguments, to allow for simpler method decorators, such as: ```ruby cached private def foo; some_long_calculation; end ``` Where cached sets up caching for the method. For each of these methods, the following behavior is used: 1) No arguments returns nil 2) Single argument is returned 3) Multiple arguments are returned as an array The single argument case is really the case we are trying to optimize for, for the same reason that def was changed to return a symbol for the method. Idea and initial patch from Herwin Quarantainenet. Implements [Feature #12495] Notes: Merged: https://github.com/ruby/ruby/pull/5037
2021-09-24Use the flag for uninitialized module [Bug #18185]Nobuyoshi Nakada
Make `Module#ancestors` not to include `BasicObject`. Notes: Merged: https://github.com/ruby/ruby/pull/4883
2021-09-24Consider modified modules initialized [Bug #18185]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4883
2021-09-20Allow to include uninitialized modules [Bug #18177]Nobuyoshi Nakada
The module that is about to be included is considered initialized. Notes: Merged: https://github.com/ruby/ruby/pull/4868
2021-09-17Removed Module.allocate [Bug #17048]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4858
2021-09-17Already initialized modules cannot be replaced [Bug #17048]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/4858
2021-09-11Fixed inconsistent require order for assertions and core_assertionsHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/4813
2021-09-11Use CoreAssertions instead of AssertionsHiroshi SHIBATA
Notes: Merged: https://github.com/ruby/ruby/pull/4813
2021-06-30Use Module#ancestors order in recursive constant lookupAlan Wu
Before this commit, const_get with inherit=true and constant lookup expressions searched the ancestors of the starting point in an order different from `starting_point.ancestors`. Items in the ancestry list introduced through prepend were searched after searching the module they were prepended into. This oddity allowed for situations where constant lookups gave different results even though `starting_point.ancestors` is the same. Do the lookup in the same order as `starting_point.ancestors` by skipping classes and modules that have an origin iclass. The origin iclass is in the super chain after the prepended modules. Note that just like before this commit, the starting point of the constant lookup is always the first item that we search, regardless of the presence of any prepended modules. [Bug #17887] Notes: Merged: https://github.com/ruby/ruby/pull/4585
2021-06-29[WIP] add error_squiggle gemYusuke Endoh
``` $ ./local/bin/ruby -e '1.time {}' -e:1:in `<main>': undefined method `time' for 1:Integer (NoMethodError) 1.time {} ^^^^^ Did you mean? times ``` https://bugs.ruby-lang.org/issues/17930 Notes: Merged: https://github.com/ruby/ruby/pull/4586
2021-04-23Fix setting method visibility for a refinement without an origin classJeremy Evans
If a class has been refined but does not have an origin class, there is a single method entry marked with VM_METHOD_TYPE_REFINED, but it contains the original method entry. If the original method entry is present, we shouldn't skip the method when searching even when skipping refined methods. Fixes [Bug #17519] Notes: Merged: https://github.com/ruby/ruby/pull/4357
2021-03-16Skip refined method when exporting methods with changed visibilityJeremy Evans
Previously, attempting to change the visibility of a method in a singleton class for a class/module that is prepended to and refined would raise a NoMethodError. Fixes [Bug #17519] Notes: Merged: https://github.com/ruby/ruby/pull/4200
2021-02-22Check for cyclic prepend before making originAlan Wu
It's important to only make the origin when the prepend goes through, as the precense of the origin informs whether to do an origin backfill. This plus 2d877327e fix [Bug #17590]. Notes: Merged: https://github.com/ruby/ruby/pull/4181
2021-02-11Make a cyclic prepend not modify ancestors for the receiverJeremy Evans
Check for cyclic prepend before making any changes. This requires scanning the module ancestor chain twice, but in general modules do not have large numbers of ancestors. Notes: Merged: https://github.com/ruby/ruby/pull/4165
2021-01-14Make Module#prepend affect ancestor chain even if argument already included ↵Jeremy Evans
in receiver Previously, if a class included a module and then prepended the same module, the prepend had no effect. This changes the behavior so that the prepend has an effect unless the module is already prepended the receiver. While here, rename the origin_seen variable in include_modules_at, since it is misleading. The variable tracks whether c has been seen, not whether the origin of klass has been. Fixes [Bug #17423] Notes: Merged: https://github.com/ruby/ruby/pull/4072
2021-01-11Suppress constant redefinition warningsNobuyoshi Nakada
2020-12-24test/ruby/test_module.rb: not depend on the order of method definitionsYusuke Endoh
2020-12-24Module#public_class_method also accepts a symbol array as an argumentYusuke Endoh
I'm unsure if this is intentional, but add a document anyway. [Feature #17314]
2020-12-19test/ruby/test_module.rb: Avoid "warning: method redefined"Yusuke Endoh
2020-12-19Recommit 34f06062174882a98ebef998c50ad8d4f7fc0f2eYusuke Endoh
2020-12-19Partially reintroduce e042e8460bb9a63c05f938d51e8c7c5345a6f3a4 and ...Yusuke Endoh
34f06062174882a98ebef998c50ad8d4f7fc0f2e Add a test for alias_method
2020-12-19Added missing tests for public, private, protected and alias_methodNobuyoshi Nakada
2020-12-19Added tests for [Feature #17314]Yusuke Endoh
Partially reintroduce 34f06062174882a98ebef998c50ad8d4f7fc0f2e
2020-12-18Use category: :deprecated in warnings that are related to deprecationJeremy Evans
Also document that both :deprecated and :experimental are supported :category option values. The locations where warnings were marked as deprecation warnings was previously reviewed by shyouhei. Comment a couple locations where deprecation warnings should probably be used but are not currently used because deprecation warning enablement has not occurred at the time they are called (RUBY_FREE_MIN, RUBY_HEAP_MIN_SLOTS, -K). Add assert_deprecated_warn to test assertions. Use this to simplify some tests, and fix failing tests after marking some warnings with deprecated category. Notes: Merged: https://github.com/ruby/ruby/pull/3917
2020-12-18Revert "Added missing tests for public, private, protected and alias_method"Yusuke Endoh
This reverts commit e042e8460bb9a63c05f938d51e8c7c5345a6f3a4.
2020-12-18Revert "Added tests for [Feature #17314]"Yusuke Endoh
This reverts commit 34f06062174882a98ebef998c50ad8d4f7fc0f2e.
2020-12-18Added tests for [Feature #17314]Nobuyoshi Nakada
2020-12-18Added missing tests for public, private, protected and alias_methodNobuyoshi Nakada
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>