Skip to content

Commit 754db2b

Browse files
committed
Initialize $0 to a String as RubyGems expects it to
1 parent 04afba2 commit 754db2b

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Bug fixes:
55
* The debugger now sees global variables as the global scope.
66
* Temporary variables are no longer visible in the debugger.
77
* Setting breakpoints on some lines has been fixed.
8+
* Initialize `$0` when not run from the 'ruby' launcher, which is needed to `require` gems (#1653).
89

910
Compatibility:
1011

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,10 @@ private void afterLoadCoreLibrary() {
849849
assert Layouts.CLASS.isClass(eagainWaitWritable);
850850

851851
findGlobalVariableStorage();
852+
853+
// Initialize $0 so it is set to a String as RubyGems expect, also when not run from the RubyLauncher
854+
DynamicObject dollarZeroValue = StringOperations.createString(context, StringOperations.encodeRope("-", USASCIIEncoding.INSTANCE, CodeRange.CR_7BIT));
855+
getContext().getCoreLibrary().getGlobalVariables().getStorage("$0").setValueInternal(dollarZeroValue);
852856
}
853857

854858
@TruffleBoundary

0 commit comments

Comments
 (0)