-
-
Notifications
You must be signed in to change notification settings - Fork 921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not every class has a superclass? #4528
Comments
I believe this is a small bug in each_object: it is returning modules as well as classes for |
Ah, awesome, so it would be a good fix. Perhaps even a candidate for a spec? |
Actually it looks even narrower. I'm only seeing a small handful of these unusual modules. They shouldn't be coming up at all.
Only one of these modules has a name: |
Ahh, they are indeed the pseudo-modules we use to represent the Java package structure:
I'll try to figure out why they're being returned. |
Hmm, I thought this patch would help but it doesn't seem to. Any thoughts on this one @kares? diff --git a/core/src/main/java/org/jruby/javasupport/JavaPackage.java b/core/src/main/java/org/jruby/javasupport/JavaPackage.java
index cea546e..a5f06f9 100644
--- a/core/src/main/java/org/jruby/javasupport/JavaPackage.java
+++ b/core/src/main/java/org/jruby/javasupport/JavaPackage.java
@@ -61,6 +61,7 @@ public class JavaPackage extends RubyModule {
RubyClass superClass = new BlankSlateWrapper(runtime, runtime.getModule(), runtime.getKernel());
RubyClass JavaPackage = RubyClass.newClass(runtime, superClass);
JavaPackage.setMetaClass(runtime.getModule());
+ JavaPackage.kindOf = runtime.getModule().kindOf;
JavaPackage.setAllocator(ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
((MetaClass) JavaPackage.makeMetaClass(superClass)).setAttached(JavaPackage);
|
Oh wait, I know why. It's the reverse problem. When ObjectSpace does This will take some thought. Seems like we need to make the blank slate package modules to actually descend from RubyModule instead. |
We worked around the problem by using a different approach, but I think it's important to fix this issue too, especially if it's not the same as what MRI does? |
@ioquatix I agree. |
najs, edgy (in the sense that its not obvious) case with those wrappers - haven't thought about it. |
I agree...this is fairly low impact to leave it as is for 9.1.9.0 but we can switch to a RubyModule subclass soon (nowish) for 9.2 on the ruby-2.4 branch and let it bake. |
This is an alternative way to fix this particular issue: just make "superclass" call "singleton_class": diff --git a/core/src/main/java/org/jruby/javasupport/JavaPackage.java b/core/src/main/java/org/jruby/javasupport/JavaPackage.java
index cea546e..4c55eb5 100644
--- a/core/src/main/java/org/jruby/javasupport/JavaPackage.java
+++ b/core/src/main/java/org/jruby/javasupport/JavaPackage.java
@@ -379,6 +379,7 @@ public class JavaPackage extends RubyModule {
// NOTE: these should maybe get re-thought and deprecated (for now due compatibility)
case "__constants__" : return "constants";
case "__methods__" : return "methods";
+ case "superclass": return "singleton_class";
}
final int last = name.length() - 1; It occurred to me that we can't really make the blank slate actually just extend RubyModule because there's plenty of other odd behavior that would come from having an object whose .class is a module rather than a class. We really just want this thing to be a blank slate. I suspect the logic here predates the existence of BasicObject, which would be a better superclass for this case. Moving that direction might clean up a lot of weird issues we've had over the years with the package modules. |
right, I recall know -> as not sure I get the benefit of |
looking into this one, seems I am able to get it right but than to test this I hit another (hard-to-track) one : since we tend to self reflect (in tests but not just there), e.g. cleaning up test, for now, hopefully we can avoid most of it so that we guard against self-reflecting too much ... |
... into native Java tests - otherwise we can not test jruby#4528
... into native Java tests - otherwise we can not test jruby#4528
there's some less self-reflection in 9.2.0 and hopefully much less in 9.2.1 ... due the standardized way of extension loading. a default boot (with JRuby's shipped gems) will than not do much JI or at least none causing |
What is left for this issue to be resolved? |
JRuby's common (and internal) ext are now updated and by default JRuby does not cause self-reflection, some external native extensions still might. regarding the issue only the JavaPackage case is left wout superclass:
|
to address common behavior of Class even if its a "fake" one (jrubyGH-4528)
to address common behavior of Class even if its a "fake" one (GH-4528)
put in a work-around so that the custom internals of |
Thanks for your huge effort to improve compatibility in this area! |
It seems like sometimes
ObjectSpace.each_object(Class).collect(&:superclass)
may fail in JRuby but works fine in MRI.Example of failure here: https://travis-ci.org/rubyworks/facets/jobs/209292853
The text was updated successfully, but these errors were encountered: