@@ -4157,11 +4157,9 @@ private boolean constDefined(Ruby runtime, IRubyObject name, boolean inherit) {
4157
4157
int patternIndex ;
4158
4158
int index = 0 ;
4159
4159
RubyModule mod = this ;
4160
- boolean includeObject = false ;
4161
4160
4162
4161
if (value .startsWith (pattern )) {
4163
4162
mod = runtime .getObject ();
4164
- includeObject = true ;
4165
4163
currentOffset += 2 ;
4166
4164
}
4167
4165
@@ -4206,7 +4204,7 @@ private boolean constDefined(Ruby runtime, IRubyObject name, boolean inherit) {
4206
4204
4207
4205
String id = RubySymbol .newConstantSymbol (runtime , fullName , lastSegment ).idString ();
4208
4206
4209
- return mod .getConstantSkipAutoload (id , inherit , includeObject ) != null ;
4207
+ return mod .getConstantSkipAutoload (id , inherit , false ) != null ;
4210
4208
}
4211
4209
4212
4210
// MRI: rb_mod_const_get
@@ -4813,10 +4811,10 @@ public IRubyObject getConstantNoConstMissing(String name, boolean inherit) {
4813
4811
}
4814
4812
4815
4813
public IRubyObject getConstantNoConstMissing (String name , boolean inherit , boolean includeObject ) {
4816
- IRubyObject constant = iterateConstantNoConstMissing (name , this , inherit , true );
4814
+ IRubyObject constant = iterateConstantNoConstMissing (name , this , inherit , true , includeObject );
4817
4815
4818
4816
if (constant == null && !isClass () && includeObject ) {
4819
- constant = iterateConstantNoConstMissing (name , getRuntime ().getObject (), inherit , true );
4817
+ constant = iterateConstantNoConstMissing (name , getRuntime ().getObject (), inherit , true , includeObject );
4820
4818
}
4821
4819
4822
4820
return constant ;
@@ -4833,10 +4831,10 @@ public IRubyObject getConstantNoConstMissingSKipAutoload(String name) {
4833
4831
4834
4832
// returns null for autoloads that have failed
4835
4833
private IRubyObject getConstantSkipAutoload (String name , boolean inherit , boolean includeObject ) {
4836
- IRubyObject constant = iterateConstantNoConstMissing (name , this , inherit , false );
4834
+ IRubyObject constant = iterateConstantNoConstMissing (name , this , inherit , false , includeObject );
4837
4835
4838
4836
if (constant == null && !isClass () && includeObject ) {
4839
- constant = iterateConstantNoConstMissing (name , getRuntime ().getObject (), inherit , false );
4837
+ constant = iterateConstantNoConstMissing (name , getRuntime ().getObject (), inherit , false , includeObject );
4840
4838
}
4841
4839
4842
4840
return constant ;
@@ -4860,8 +4858,9 @@ private static SourceLocation iterateConstantEntryNoConstMissing(String name, Ru
4860
4858
}
4861
4859
4862
4860
private static IRubyObject iterateConstantNoConstMissing (String name ,
4863
- RubyModule init , boolean inherit , boolean loadConstant ) {
4861
+ RubyModule init , boolean inherit , boolean loadConstant , boolean includeObject ) {
4864
4862
for (RubyModule mod = init ; mod != null ; mod = mod .getSuperClass ()) {
4863
+ if (!includeObject && mod == init .getRuntime ().getObject ()) break ;
4865
4864
IRubyObject value =
4866
4865
loadConstant ?
4867
4866
mod .getConstantWithAutoload (name , null , true ) :
0 commit comments