Skip to content

Check irb_require loaded files against the load path - #1262

Open
Shaisolaris wants to merge 2 commits into
ruby:masterfrom
Shaisolaris:irb-require-loaded-check
Open

Shaisolaris wants to merge 2 commits into
ruby:masterfrom
Shaisolaris:irb-require-loaded-check

Conversation

@Shaisolaris

Copy link
Copy Markdown

Since #1254, the already-loaded check in irb_require matches any $LOADED_FEATURES entry that ends with /<name>.rb. A file with the same basename in another directory now counts as loaded, so irb_require skips the requested file and returns false.

For example, with util.rb in a directory on the load path:

irb> irb_require 'util'
=> false        # rubygems/util.rb is in $LOADED_FEATURES; util.rb is not loaded

The same happens for names like set, parser or version once a library with such a file (for example psych/set.rb) has been loaded.

This change compares the entries with the names irb_require itself pushes and with <dir>/<name>, <dir>/<name>.rb and <dir>/<name>.o for each $LOAD_PATH directory. A file that require loaded from the load path is still skipped, so test_irb_require_skips_file_already_loaded_by_require from #1254 and the foo/foo2 test from #1253 still pass.

Tests:

  • Added test_irb_require_loads_file_with_same_name_as_loaded_file_in_other_directory. It fails on master and passes with this change.
  • test/irb/test_command.rb: 57 tests pass locally (Ruby 3.3.8).
  • All test/irb/test_*.rb files loaded together: the same 2 failures on master and with this change (test_object_inspection_handles_basic_object, test_use_tracer_enabled_when_gem_is_available), so they are not related. I did not run RuboCop or the CI matrix.

#1257 also changes irb_require (the .rb branch); the two changes touch different lines.

The already-loaded check matched any $LOADED_FEATURES entry that ends
with /name.rb, so a file loaded from another directory with the same
basename made irb_require skip the requested file and return false.
For example, irb_require 'util' did nothing because
rubygems/util.rb is loaded.

Compare against the names irb_require pushes and the paths under each
$LOAD_PATH directory instead.
The file loaded with Kernel#require contained a bare string literal,
which prints "possibly useless use of a literal in void context" when
warnings are enabled, so assert_empty(err) failed in CI.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant