Skip to content

Commit 8cd2203

Browse files
committed
[GR-18163] Fix interop source_location to return unavailable source sections for modules instead of null
PullRequest: truffleruby/2441
2 parents b5e132c + 9645a88 commit 8cd2203

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Bug fixes:
1616
* Fix extra whitespace in squiggly heredoc with escaped newline (#2238, @wildmaples and @norswap).
1717
* Fix handling of signals with `--single-threaded` (#2265).
1818
* Fix `Enumerator::Lazy#{chunk_while, slice_before, slice_after, slice_when}` to return instances of `Enumerator::Lazy` (#2273).
19+
* Fix `Truffle::Interop.source_location` to return unavailable source sections for modules instead of null (#2257).
1920

2021
Compatibility:
2122

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 2.0, or
6+
# GNU General Public License version 2, or
7+
# GNU Lesser General Public License version 2.1.
8+
9+
require_relative '../../ruby/spec_helper'
10+
require_relative 'fixtures/classes'
11+
12+
describe "Truffle::Interop source messages" do
13+
it "returns correct source location" do
14+
method = Array.instance_method(:each_index)
15+
Truffle::Interop.has_source_location?(method).should == true
16+
Truffle::Interop.to_display_string(Truffle::Interop.source_location(method)).should include("array.rb")
17+
18+
Truffle::Interop.has_source_location?(Array).should == true
19+
Truffle::Interop.to_display_string(Truffle::Interop.source_location(Array)).should include("(unavailable)")
20+
21+
Truffle::Interop.has_source_location?(ObjectSpace).should == true
22+
Truffle::Interop.to_display_string(Truffle::Interop.source_location(ObjectSpace)).should include("(unavailable)")
23+
end
24+
end

src/main/java/org/truffleruby/core/module/RubyModule.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.oracle.truffle.api.nodes.Node;
1515
import org.truffleruby.RubyContext;
1616
import org.truffleruby.RubyLanguage;
17+
import org.truffleruby.core.CoreLibrary;
1718
import org.truffleruby.core.klass.RubyClass;
1819
import org.truffleruby.language.RubyDynamicObject;
1920
import org.truffleruby.language.Visibility;
@@ -112,7 +113,12 @@ public boolean hasSourceLocation() {
112113

113114
@ExportMessage
114115
public SourceSection getSourceLocation() {
115-
return fields.getSourceSection();
116+
SourceSection sourceSection = fields.getSourceSection();
117+
if (sourceSection != null) {
118+
return sourceSection;
119+
} else {
120+
return CoreLibrary.UNAVAILABLE_SOURCE_SECTION;
121+
}
116122
}
117123
// endregion
118124

0 commit comments

Comments
 (0)