Module#parent_name broken for frozen classes #27713

Merged
merged 1 commit into from Jan 18, 2017

Projects

None yet

5 participants

@coreyward
Contributor

Previously memoization inside of Module.parent_name resulted in a runtime error when called for the first time on a frozen module. This patch adds a regression test and refactors the method to resolve the issue.

Note: introspection tests were previously lumped into test/core_ext/module_test.rb despite the code having been extracted to core_exts/module/introspection.rb. I isolated the tests similarly, following convention (e.g., core_exts/module/anonymous.rb to test/core_ext/module/anonymous_test.rb). In the process, I removed some old (over 10 years) setup objects that were no longer being referenced.

@rails-bot

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @eileencodes (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@maclover7
Member

ref #27637

@maclover7

Can you squash down to one commit? Otherwise looks good to me. Thanks for working on this!

@coreyward
Contributor

Done!

- else
- @parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
- end
+ return @parent_name if defined?(@parent_name)
@rafaelfranca
rafaelfranca Jan 18, 2017 Member

Can we keep the if/else where. We prefer it over short-circuit returns.

@coreyward coreyward Adjust `Module.parent_name` to work when frozen; fixes #27637
1d3ddac
@coreyward
Contributor

@rafaelfranca Updated to reflect your concerns.

Cheers!

@rafaelfranca rafaelfranca merged commit 5ac8af2 into rails:master Jan 18, 2017

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
codeclimate no new or fixed issues
Details
@coreyward coreyward deleted the coreyward:module_freeze_parent_name branch Jan 18, 2017
@rafaelfranca
Member

Backported 9f4fc67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment