Skip to content

Commit 96e2452

Browse files
committed
[GR-20250] Fix Symbol#to_proc to create proc with nil source_location (#1663).
PullRequest: truffleruby/1204
2 parents 4d41d46 + 30bdf78 commit 96e2452

File tree

7 files changed

+16
-8
lines changed

7 files changed

+16
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Bug fixes:
4747
* Fixed `BigDecimal#to_s` formatting issue (#1711).
4848
* Run `END` keyword block only once at exit.
4949
* Implement Numeric#clone method to return self.
50+
* Fixed `Symbol#to_proc` to create proc with nil `source_location` (#1663).
5051

5152
Compatibility:
5253

spec/ruby/core/symbol/to_proc_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@ def to_proc
3838
end
3939
klass.new.to_proc.should == :value
4040
end
41+
42+
it "produces a proc with source location nil" do
43+
pr = :to_s.to_proc
44+
pr.source_location.should == nil
45+
end
4146
end

src/main/java/org/truffleruby/core/CoreLibrary.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@
7979

8080
public class CoreLibrary {
8181

82+
public static final SourceSection UNAVAILABLE_SOURCE_SECTION = Source
83+
.newBuilder(TruffleRuby.LANGUAGE_ID, "", "(unavailable)")
84+
.build()
85+
.createUnavailableSection();
86+
8287
private static final String ERRNO_CONFIG_PREFIX = NativeConfiguration.PREFIX + "errno.";
8388

8489
private static final Property ALWAYS_FROZEN_PROPERTY = Property

src/main/java/org/truffleruby/core/method/MethodNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public abstract static class SourceLocationNode extends CoreMethodArrayArguments
181181
protected Object sourceLocation(DynamicObject method) {
182182
SourceSection sourceSection = Layouts.METHOD.getMethod(method).getSharedMethodInfo().getSourceSection();
183183

184-
if (sourceSection.getSource() == null) {
184+
if (!sourceSection.isAvailable()) {
185185
return nil();
186186
} else {
187187
DynamicObject file = makeStringNode.executeMake(

src/main/java/org/truffleruby/core/method/UnboundMethodNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ protected Object sourceLocation(DynamicObject unboundMethod) {
178178
.getSharedMethodInfo()
179179
.getSourceSection();
180180

181-
if (sourceSection.getSource() == null) {
181+
if (!sourceSection.isAvailable()) {
182182
return nil();
183183
} else {
184184
DynamicObject file = makeStringNode.executeMake(

src/main/java/org/truffleruby/core/proc/ProcNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public abstract static class SourceLocationNode extends CoreMethodArrayArguments
286286
protected Object sourceLocation(DynamicObject proc) {
287287
SourceSection sourceSection = Layouts.PROC.getSharedMethodInfo(proc).getSourceSection();
288288

289-
if (sourceSection.getSource() == null ||
289+
if (!sourceSection.isAvailable() ||
290290
sourceSection.getSource().getName().endsWith("/lib/truffle/truffle/cext.rb")) {
291291
return nil();
292292
} else {

src/main/java/org/truffleruby/core/symbol/SymbolNodes.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.truffleruby.builtins.CoreMethod;
1616
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
1717
import org.truffleruby.builtins.UnaryCoreMethodNode;
18+
import org.truffleruby.core.CoreLibrary;
1819
import org.truffleruby.core.proc.ProcOperations;
1920
import org.truffleruby.core.proc.ProcType;
2021
import org.truffleruby.core.string.StringNodes;
@@ -122,11 +123,7 @@ protected DynamicObject toProcUncached(VirtualFrame frame, DynamicObject symbol)
122123
@TruffleBoundary
123124
protected DynamicObject createProc(DeclarationContext declarationContext, InternalMethod method,
124125
DynamicObject symbol) {
125-
final SourceSection sourceSection = getContext()
126-
.getCallStack()
127-
.getCallerNodeIgnoringSend()
128-
.getEncapsulatingSourceSection();
129-
126+
final SourceSection sourceSection = CoreLibrary.UNAVAILABLE_SOURCE_SECTION;
130127
final SharedMethodInfo sharedMethodInfo = new SharedMethodInfo(
131128
sourceSection,
132129
method.getLexicalScope(),

0 commit comments

Comments
 (0)