Skip to content

Commit 7fdec90

Browse files
committed
[Truffle] Handle #to_s on String subclasses.
1 parent a6fc17e commit 7fdec90

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

spec/truffle/tags/core/string/to_s_tags.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

truffle/src/main/java/org/jruby/truffle/nodes/core/StringNodes.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,10 +1727,20 @@ public ToSNode(ToSNode prev) {
17271727
super(prev);
17281728
}
17291729

1730-
@Specialization
1730+
@Specialization(guards = "!isStringSubclass")
17311731
public RubyString toS(RubyString string) {
17321732
return string;
17331733
}
1734+
1735+
@Specialization(guards = "isStringSubclass")
1736+
public Object toSOnSubclass(VirtualFrame frame, RubyString string) {
1737+
return ruby(frame, "''.replace(self)", "self", string);
1738+
}
1739+
1740+
public boolean isStringSubclass(RubyString string) {
1741+
return string.getLogicalClass() != getContext().getCoreLibrary().getStringClass();
1742+
}
1743+
17341744
}
17351745

17361746
@CoreMethod(names = {"to_sym", "intern"})

0 commit comments

Comments
 (0)