Skip to content

Commit 833904b

Browse files
authored
Merge pull request jruby#9237 from evaniainbrooks/8876-import-methods-2
Fix for import_methods does not allow calling another refined method
2 parents 51ace55 + 0359879 commit 833904b

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

core/src/main/java/org/jruby/RubyModule.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6880,8 +6880,20 @@ private static void refinementImportMethodsIter(ThreadContext context, RubyModul
68806880
DynamicMethod dup = entry.getValue().dup();
68816881
dup.setImplementationClass(selfModule);
68826882

6883-
// maybe insufficient if we have already compiled assuming no refinements
6884-
((AbstractIRMethod) dup).getIRScope().setIsMaybeUsingRefinements();
6883+
AbstractIRMethod dupAir = (AbstractIRMethod) dup;
6884+
dupAir.getIRScope().setIsMaybeUsingRefinements();
6885+
6886+
RubyModule definedAt = selfModule.getRefinementStoreForWrite().definedAt;
6887+
if (definedAt != null) {
6888+
Map<RubyModule, RubyModule> refinements = definedAt.getRefinements();
6889+
if (!refinements.isEmpty()) {
6890+
dupAir
6891+
.getStaticScope()
6892+
.getOverlayModuleForWrite(context)
6893+
.getRefinementsForWrite()
6894+
.putAll(refinements);
6895+
}
6896+
}
68856897

68866898
selfModule.addMethod(context, entry.getKey(), dup);
68876899
}

core/src/main/java/org/jruby/ir/IRScope.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ public IRManager getManager() {
246246

247247
public void setIsMaybeUsingRefinements() {
248248
maybeUsingRefinements = true;
249+
fullInterpreterContext = null;
249250
}
250251

251252
public boolean parentMaybeUsingRefinements() {

core/src/main/java/org/jruby/ir/instructions/CallBase.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,26 @@ protected CallBase(IRScope scope, Operation op, CallType callType, RubySymbol na
6464
hasClosure = closure != NullBlock.INSTANCE;
6565
this.name = name;
6666
this.callType = callType;
67-
this.callSite = callSite == null ? getCallSiteFor(scope, callType, name.idString(), callSiteId, hasLiteralClosure(), potentiallyRefined) : callSite;
67+
68+
boolean effectivelyRefined = potentiallyRefined || (scope != null && scope.maybeUsingRefinements());
69+
boolean hasUnrefinedCallSite = callSite != null && !(callSite instanceof RefinedCachingCallSite);
70+
if (effectivelyRefined && hasUnrefinedCallSite) {
71+
callSite = null;
72+
}
73+
74+
if (callSite == null) {
75+
this.callSite = getCallSiteFor(scope, callType, name.idString(), callSiteId, hasLiteralClosure(), effectivelyRefined);
76+
} else {
77+
this.callSite = callSite;
78+
}
79+
6880
splatMap = IRRuntimeHelpers.buildSplatMap(args);
6981
flagsComputed = false;
7082
canBeEval = true;
7183
targetRequiresCallersBinding = true;
7284
targetRequiresCallersFrame = true;
7385
dontInline = false;
74-
this.potentiallyRefined = potentiallyRefined;
86+
this.potentiallyRefined = effectivelyRefined;
7587

7688
captureFrameReadsAndWrites();
7789
}

spec/tags/ruby/core/refinement/import_methods_tags.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)