Skip to content

Commit 743e0c2

Browse files
committed
Fix Kernel#load(path, wrap=true) and pass all specs
1 parent 977c82b commit 743e0c2

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Bug fixes:
2727
* Keep the Truffle working directory in sync with the native working directory.
2828
* Rename `to_native` to `polyglot_to_native` to match `polyglot_pointer?` and `polyglot_address` methods.
2929
* Fixed missing partial evaluation boundary in `Array#{sort,sort!}` (#1727).
30+
* Fixed the class of `self` and the wrapping `Module` for `Kernel#load(path, wrap=true)` (#1739).
3031

3132
Compatibility:
3233

src/main/java/org/truffleruby/core/kernel/TruffleKernelNodes.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@
1212
import java.io.IOException;
1313

1414
import org.truffleruby.Layouts;
15-
import org.truffleruby.builtins.CoreModule;
1615
import org.truffleruby.builtins.CoreMethod;
1716
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
1817
import org.truffleruby.builtins.CoreMethodNode;
18+
import org.truffleruby.builtins.CoreModule;
1919
import org.truffleruby.builtins.Primitive;
2020
import org.truffleruby.core.cast.BooleanCastWithDefaultNodeGen;
21-
import org.truffleruby.core.klass.ClassNodes;
21+
import org.truffleruby.core.module.ModuleNodes;
2222
import org.truffleruby.core.string.StringOperations;
2323
import org.truffleruby.language.RubyNode;
2424
import org.truffleruby.language.RubyRootNode;
2525
import org.truffleruby.language.control.RaiseException;
26+
import org.truffleruby.language.dispatch.CallDispatchHeadNode;
2627
import org.truffleruby.language.globals.ReadSimpleGlobalVariableNode;
2728
import org.truffleruby.language.globals.WriteSimpleGlobalVariableNode;
2829
import org.truffleruby.language.loader.CodeLoader;
@@ -80,40 +81,37 @@ protected boolean load(DynamicObject file, boolean wrap,
8081
throw new RaiseException(getContext(), coreExceptions().loadErrorCannotLoad(feature, this));
8182
}
8283

83-
final DynamicObject wrapClass;
84-
84+
final DynamicObject wrapModule;
8585
if (wrap) {
86-
wrapClass = ClassNodes.createInitializedRubyClass(
87-
getContext(),
88-
null,
89-
null,
90-
getContext().getCoreLibrary().getObjectClass(),
91-
null);
86+
wrapModule = ModuleNodes
87+
.createModule(getContext(), null, coreLibrary().getModuleClass(), null, null, this);
9288
} else {
93-
wrapClass = null;
89+
wrapModule = null;
9490
}
9591

9692
final RubyRootNode rootNode = getContext()
9793
.getCodeLoader()
98-
.parse(source, ParserContext.TOP_LEVEL, null, wrapClass, true, this);
94+
.parse(source, ParserContext.TOP_LEVEL, null, wrapModule, true, this);
9995

96+
final DynamicObject mainObject = getContext().getCoreLibrary().getMainObject();
10097
final DeclarationContext declarationContext;
101-
final DynamicObject mainObject;
98+
final Object self;
10299

103-
if (wrapClass == null) {
100+
if (wrapModule == null) {
104101
declarationContext = DeclarationContext.topLevel(getContext());
105-
mainObject = getContext().getCoreLibrary().getMainObject();
102+
self = mainObject;
106103
} else {
107-
declarationContext = DeclarationContext.topLevel(wrapClass);
108-
mainObject = Layouts.CLASS.getInstanceFactory(wrapClass).newInstance();
104+
declarationContext = DeclarationContext.topLevel(wrapModule);
105+
self = CallDispatchHeadNode.getUncached().call(mainObject, "clone");
106+
CallDispatchHeadNode.getUncached().call(self, "extend", wrapModule);
109107
}
110108

111109
final CodeLoader.DeferredCall deferredCall = getContext().getCodeLoader().prepareExecute(
112110
ParserContext.TOP_LEVEL,
113111
declarationContext,
114112
rootNode,
115113
null,
116-
mainObject);
114+
self);
117115

118116
deferredCall.call(callNode);
119117

0 commit comments

Comments
 (0)