Skip to content

Commit 8b0e25d

Browse files
committed
Revert "[Truffle] :: looks up constants slightly differently."
This reverts commit d3df63c. Conflicts: core/src/main/java/org/jruby/truffle/nodes/ReadConstantNode.java
1 parent 6be98c4 commit 8b0e25d

4 files changed

Lines changed: 13 additions & 21 deletions

File tree

‎core/src/main/java/org/jruby/truffle/nodes/ReadConstantNode.java‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,28 @@
2020
import org.jruby.truffle.runtime.*;
2121
import org.jruby.truffle.runtime.control.*;
2222
import org.jruby.truffle.runtime.core.RubyBasicObject;
23-
import org.jruby.truffle.runtime.core.RubyModule;
2423

2524
public class ReadConstantNode extends RubyNode {
2625

27-
private final boolean isLiteral;
28-
private final String name;
29-
@Child protected RubyNode receiver;
26+
protected final String name;
27+
@Child protected BoxingNode receiver;
28+
3029
@Child protected DispatchHeadNode dispatch;
3130

32-
public ReadConstantNode(RubyContext context, SourceSection sourceSection, boolean isLiteral, String name, RubyNode receiver) {
31+
public ReadConstantNode(RubyContext context, SourceSection sourceSection, String name, RubyNode receiver) {
3332
super(context, sourceSection);
34-
this.isLiteral = isLiteral;
3533
this.name = name;
36-
this.receiver = receiver;
34+
this.receiver = new BoxingNode(context, sourceSection, receiver);
3735
dispatch = new DispatchHeadNode(context, Dispatch.MissingBehavior.CALL_CONST_MISSING);
3836
}
3937

4038
@Override
4139
public Object execute(VirtualFrame frame) {
42-
final Object receiverObject = receiver.execute(frame);
43-
44-
if (isLiteral && !(receiverObject instanceof RubyModule)) {
45-
CompilerDirectives.transferToInterpreter();
46-
throw new RaiseException(getContext().getCoreLibrary().typeErrorIsNotA(receiverObject.toString(), "class/module", this));
47-
}
48-
4940
return dispatch.dispatch(
5041
frame,
5142
NilPlaceholder.INSTANCE,
5243
RubyArguments.getSelf(frame.getArguments()),
53-
receiverObject,
44+
receiver.executeRubyBasicObject(frame),
5445
name,
5546
null,
5647
new Object[]{},

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ public RubyNode visitClassVarNode(org.jruby.ast.ClassVarNode node) {
633633
public RubyNode visitColon2Node(org.jruby.ast.Colon2Node node) {
634634
final RubyNode lhs = node.getLeftNode().accept(this);
635635

636-
return new ReadConstantNode(context, translate(node.getPosition()), true, node.getName(), lhs);
636+
return new ReadConstantNode(context, translate(node.getPosition()), node.getName(), lhs);
637637
}
638638

639639
@Override
@@ -642,9 +642,9 @@ public RubyNode visitColon3Node(org.jruby.ast.Colon3Node node) {
642642

643643
final SourceSection sourceSection = translate(node.getPosition());
644644

645-
final ObjectLiteralNode root = new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getObjectClass());
645+
final ObjectLiteralNode root = new ObjectLiteralNode(context, sourceSection, context.getCoreLibrary().getMainObject());
646646

647-
return new ReadConstantNode(context, sourceSection, false, node.getName(), root);
647+
return new ReadConstantNode(context, sourceSection, node.getName(), root);
648648
}
649649

650650
@Override
@@ -660,7 +660,7 @@ public RubyNode visitConstDeclNode(org.jruby.ast.ConstDeclNode node) {
660660
public RubyNode visitConstNode(org.jruby.ast.ConstNode node) {
661661
final SourceSection sourceSection = translate(node.getPosition());
662662

663-
return new ReadConstantNode(context, sourceSection, false, node.getName(), new SelfNode(context, sourceSection));
663+
return new ReadConstantNode(context, sourceSection, node.getName(), new SelfNode(context, sourceSection));
664664
}
665665

666666
@Override

‎core/src/main/java/org/jruby/truffle/translator/ModuleTranslator.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public RubyNode visitConstNode(org.jruby.ast.ConstNode node) {
8282

8383
final SelfNode selfNode = new SelfNode(context, sourceSection);
8484

85-
return new ReadConstantNode(context, sourceSection, false, node.getName(), selfNode);
85+
return new ReadConstantNode(context, sourceSection, node.getName(), selfNode);
8686
}
8787

8888
@Override

‎spec/truffle/tags/language/constants_tags.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
fails:Literal (A::X) constant resolution raises a TypeError if a non-class or non-module qualifier is given
12
fails:Literal (A::X) constant resolution with statically assigned constants does not search the singleton class of the class or module
23
fails:Literal (A::X) constant resolution with dynamically assigned constants does not search the singleton class of the class or module
34
fails:Constant resolution within methods sends #const_missing to the original class or module scope
@@ -28,6 +29,6 @@ fails:Literal (A::X) constant resolution with statically assigned constants sear
2829
fails:Literal (A::X) constant resolution with statically assigned constants searches the superclass chain
2930
fails:Constant resolution within methods with statically assigned constants does not search the lexical scope of qualifying modules
3031
fails:Constant resolution within methods with dynamically assigned constants does not search the lexical scope of qualifying modules
32+
fails:Constant resolution within methods with statically assigned constants searches Object as a lexical scope only if Object is explicitly opened
3133
fails:Module#public_constant marked constants in a module is defined? with A::B form
3234
fails:Module#public_constant marked constants in a class is defined? with A::B form
33-
fails:Literal (A::X) constant resolution with statically assigned constants searches Object if a toplevel qualifier (::X) is given

0 commit comments

Comments
 (0)