Skip to content

Commit 658b588

Browse files
committed
[Truffle] Translate Rubinius to ::Rubinius in Rubinius kernel code.
Rubinius is used in classes such as BasicObject where we can't understand how it's found. This fixes that but isn't exactly the same behaviour as Rubinius, where Rubinius wouldn't be found, but Rubinius::Type would be.
1 parent 667e30f commit 658b588

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

truffle/src/main/java/org/jruby/truffle/translator/BodyTranslator.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,17 @@ public RubyNode visitConstNode(org.jruby.ast.ConstNode node) {
880880
// Unqualified constant access, as in CONST
881881
final SourceSection sourceSection = translate(node.getPosition());
882882

883+
/*
884+
* Constants of the form Rubinius::Foo in the Rubinius kernel code always seem to get resolved, even if
885+
* Rubinius is not defined, such as in BasicObject. We get around this by translating Rubinius to be
886+
* ::Rubinius. Note that this isn't quite what Rubinius does, as they say that Rubinius isn't defined, but
887+
* we will because we'll translate that to ::Rubinius. But it is a simpler translation.
888+
*/
889+
890+
if (node.getName().equals("Rubinius") && sourceSection.getSource().getPath().startsWith("core:/jruby/truffle/core/rubinius/kernel")) {
891+
return new org.jruby.ast.Colon3Node(node.getPosition(), node.getName()).accept(this);
892+
}
893+
883894
final LexicalScope lexicalScope = environment.getLexicalScope();
884895
final RubyNode moduleNode = new LexicalScopeNode(context, sourceSection, lexicalScope);
885896
return new ReadConstantNode(context, sourceSection, node.getName(), moduleNode, lexicalScope);

0 commit comments

Comments
 (0)