Skip to content

Commit b8987dc

Browse files
authored
Merge pull request #6785 from enebo/fix_6271
Fixes #6271. Prepending a module hides module's constants
2 parents 63879c5 + 0d61618 commit b8987dc

File tree

5 files changed

+44
-39
lines changed

5 files changed

+44
-39
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public String getMethodName() {
104104

105105
@JRubyMethod(name = "owner")
106106
public IRubyObject owner(ThreadContext context) {
107-
return implementationModule;
107+
return implementationModule.getOrigin();
108108
}
109109

110110
@JRubyMethod(name = "source_location")

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

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -131,21 +131,6 @@ protected void variableTableSync(List<Variable<Object>> vars) {
131131
// CONSTANT TABLE METHODS - pass to origin
132132
//
133133

134-
@Override
135-
protected boolean constantTableContains(String name) {
136-
return origin.constantTableContains(name);
137-
}
138-
139-
@Override
140-
protected IRubyObject constantTableFetch(String name) {
141-
return origin.constantTableFetch(name);
142-
}
143-
144-
@Override
145-
protected ConstantEntry constantEntryFetch(String name) {
146-
return origin.constantEntryFetch(name);
147-
}
148-
149134
@Override
150135
protected IRubyObject constantTableStore(String name, IRubyObject value) {
151136
// FIXME: legal here? may want UnsupportedOperationException
@@ -163,22 +148,6 @@ protected IRubyObject constantTableRemove(String name) {
163148
return origin.constantTableRemove(name);
164149
}
165150

166-
@Override
167-
@Deprecated
168-
public List<String> getStoredConstantNameList() {
169-
return origin.getStoredConstantNameList();
170-
}
171-
172-
@Override
173-
public Collection<String> getConstantNames() {
174-
return origin.getConstantNames();
175-
}
176-
177-
@Override
178-
public Collection<String> getConstantNames(boolean includePrivate) {
179-
return origin.getConstantNames(includePrivate);
180-
}
181-
182151
@Override
183152
protected IRubyObject getAutoloadConstant(String name, boolean forceLoad) {
184153
return origin.getAutoloadConstant(name, forceLoad);

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030
package org.jruby;
3131

32+
import java.util.Collection;
3233
import java.util.Collections;
34+
import java.util.List;
3335
import java.util.Map;
3436

3537
import org.jruby.internal.runtime.methods.DynamicMethod;
@@ -158,4 +160,40 @@ protected Map<String, IRubyObject> getClassVariablesForRead() {
158160
return origin.getClassVariablesForRead();
159161
}
160162

163+
//
164+
// CONSTANT TABLE METHODS - pass to origin
165+
//
166+
167+
@Override
168+
protected IRubyObject constantTableStore(String name, IRubyObject value) {
169+
// FIXME: legal here? may want UnsupportedOperationException
170+
return origin.constantTableStore(name, value);
171+
}
172+
173+
protected IRubyObject constantTableStore(String name, IRubyObject value, boolean hidden) {
174+
// FIXME: legal here? may want UnsupportedOperationException
175+
return origin.constantTableStore(name, value, hidden);
176+
}
177+
178+
@Override
179+
protected IRubyObject constantTableRemove(String name) {
180+
// this _is_ legal (when removing an undef)
181+
return origin.constantTableRemove(name);
182+
}
183+
184+
@Override
185+
protected IRubyObject getAutoloadConstant(String name, boolean forceLoad) {
186+
return origin.getAutoloadConstant(name, forceLoad);
187+
}
188+
189+
@Override
190+
protected Map<String, Autoload> getAutoloadMap() {
191+
return origin.getAutoloadMap();
192+
}
193+
194+
@Override
195+
protected Map<String, Autoload> getAutoloadMapForWrite() {
196+
return origin.getAutoloadMapForWrite();
197+
}
198+
161199
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public boolean isInstance(IRubyObject object) {
306306
}
307307

308308
public Map<String, ConstantEntry> getConstantMap() {
309-
return constants;
309+
return getOrigin().constants;
310310
}
311311

312312
public Map<String, ConstantEntry> getConstantMapForWrite() {
@@ -3579,8 +3579,8 @@ private void doPrependModule(RubyModule baseModule) {
35793579
* @return A list of all modules that would be included by including the given module
35803580
*/
35813581
private List<RubyModule> gatherModules(RubyModule baseModule) {
3582-
// build a list of all modules to consider for inclusion
3583-
List<RubyModule> modulesToInclude = new ArrayList<RubyModule>();
3582+
List<RubyModule> modulesToInclude = new ArrayList<>();
3583+
35843584
for (; baseModule != null; baseModule = baseModule.superClass) {
35853585
// skip prepended roots
35863586
if (baseModule != baseModule.getMethodLocation()) continue;
@@ -4967,7 +4967,7 @@ public List<Variable<IRubyObject>> getStoredConstantList() {
49674967

49684968
@Deprecated
49694969
public List<String> getStoredConstantNameList() {
4970-
return new ArrayList<String>(getConstantMap().keySet());
4970+
return new ArrayList<>(getConstantMap().keySet());
49714971
}
49724972

49734973
/**
@@ -4984,7 +4984,7 @@ public Collection<String> getConstantNames(boolean includePrivate) {
49844984
return Collections.EMPTY_SET;
49854985
}
49864986

4987-
HashSet<String> publicNames = new HashSet<String>(getConstantMap().size());
4987+
HashSet<String> publicNames = new HashSet<>(getConstantMap().size());
49884988

49894989
for (Map.Entry<String, ConstantEntry> entry : getConstantMap().entrySet()) {
49904990
if (entry.getValue().hidden) continue;

spec/tags/ruby/core/module/prepend_tags.txt

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

0 commit comments

Comments
 (0)