Skip to content

Commit 3c337b7

Browse files
committed
[GR-18163] Convert objects with #to_path in $LOAD_PATH (#2119)
PullRequest: truffleruby/2059
2 parents cbd20ec + e580ae3 commit 3c337b7

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Compatibility:
4646
* Module#using raises error in method scope (#2112, @ssnickolay)
4747
* `File#path` now returns a new mutable String on every call like MRI (#2115).
4848
* Avoid infinite recursion when redefining `Warning#warn` and calling `Kernel#warn` (#2109).
49+
* Convert objects with `#to_path` in `$LOAD_PATH` (#2119).
4950

5051
Performance:
5152

spec/ruby/core/kernel/shared/require.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@
160160
ScratchPad.recorded.should == [:loaded]
161161
end
162162

163+
it "accepts an Object with #to_path in $LOAD_PATH" do
164+
obj = mock("to_path")
165+
obj.should_receive(:to_path).at_least(:once).and_return(CODE_LOADING_DIR)
166+
$LOAD_PATH << obj
167+
@object.send(@method, "load_fixture.rb").should be_true
168+
ScratchPad.recorded.should == [:loaded]
169+
end
170+
163171
it "does not require file twice after $LOAD_PATH change" do
164172
$LOAD_PATH << CODE_LOADING_DIR
165173
@object.require("load_fixture.rb").should be_true

src/main/ruby/truffleruby/core/truffle/feature_loader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ def self.features_index_add(feature, offset)
279279

280280
def self.get_expanded_load_path
281281
unless Primitive.array_storage_equal?(@load_path_copy, $LOAD_PATH)
282-
@expanded_load_path = $LOAD_PATH.map { |path| Primitive.canonicalize_path(path) }
282+
@expanded_load_path = $LOAD_PATH.map { |path| Primitive.canonicalize_path(Truffle::Type.coerce_to_path(path)) }
283283
@loaded_features_copy = $LOAD_PATH.dup
284284
end
285285
@expanded_load_path

0 commit comments

Comments
 (0)