Skip to content

Commit e493936

Browse files
committed
Do not replace an AutoloadConstant with the same path
(cherry picked from commit b0c5a2b)
1 parent e690de0 commit e493936

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/main/java/org/truffleruby/core/module/ModuleFields.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,21 @@ private RubyConstant setConstantInternal(RubyContext context, Node currentNode,
371371

372372
SharedObjects.propagate(context, rubyModule, value);
373373

374+
final String autoloadPath = autoload ? ((RubyString) value).getJavaString() : null;
374375
RubyConstant previous;
375376
RubyConstant newConstant;
376377
do {
377378
previous = constants.get(name);
378-
if (autoload && previous != null && previous.hasValue()) {
379-
// abort, do not set an autoload constant, the constant already has a value
380-
return null;
379+
if (autoload && previous != null) {
380+
if (previous.hasValue()) {
381+
// abort, do not set an autoload constant, the constant already has a value
382+
return null;
383+
} else if (previous.isAutoload() &&
384+
previous.getAutoloadConstant().getAutoloadPath().equals(autoloadPath)) {
385+
// already an autoload constant with the same path,
386+
// do nothing so we don't replace the AutoloadConstant#autoloadLock which might be already acquired
387+
return null;
388+
}
381389
}
382390
newConstant = newConstant(currentNode, name, value, autoload, previous);
383391
} while (!ConcurrentOperations.replace(constants, name, previous, newConstant));

0 commit comments

Comments
 (0)