Skip to content
Permalink
Browse files
[Truffle] Use a stronger check for class identity.
  • Loading branch information
eregon committed Dec 29, 2014
1 parent 41bcacf commit 409925e260579a9f3bb729d70a1857a4e9b1950d
@@ -73,7 +73,7 @@ private RubyClass getRubySuperClass(VirtualFrame frame, RubyContext context) {
final Object superClassObj = superClass.execute(frame);

if (superClassObj instanceof RubyClass){
if (((RubyClass) superClassObj).isSingleton()){
if (((RubyClass) superClassObj).isSingleton()) {
throw new RaiseException(context.getCoreLibrary().typeError("can't make subclass of virtual class", this));
}

@@ -82,13 +82,13 @@ private RubyClass getRubySuperClass(VirtualFrame frame, RubyContext context) {
throw new RaiseException(context.getCoreLibrary().typeError("superclass must be a Class", this));
}

private boolean isBlankOrRootClass(RubyClass rubyClass){
return rubyClass.getName() == "BasicObject" || rubyClass.getName() == "Object";
private boolean isBlankOrRootClass(RubyClass rubyClass) {
return rubyClass == getContext().getCoreLibrary().getBasicObjectClass() || rubyClass == getContext().getCoreLibrary().getObjectClass();
}

private void checkSuperClassCompatibility(RubyContext context, RubyClass superClassObject, RubyClass definingClass){
if (!isBlankOrRootClass(superClassObject) && !isBlankOrRootClass(definingClass) && definingClass.getSuperClass().getObjectID() != superClassObject.getObjectID()){
throw new RaiseException(context.getCoreLibrary().typeError(("superclass mismatch for class " + definingClass.getName()), this));
private void checkSuperClassCompatibility(RubyContext context, RubyClass superClassObject, RubyClass definingClass) {
if (!isBlankOrRootClass(superClassObject) && !isBlankOrRootClass(definingClass) && definingClass.getSuperClass() != superClassObject) {
throw new RaiseException(context.getCoreLibrary().typeError("superclass mismatch for class " + definingClass.getName(), this));
}
}
}
@@ -686,6 +686,10 @@ public RubyClass getArrayClass() {
return arrayClass;
}

public RubyClass getBasicObjectClass() {
return basicObjectClass;
}

public RubyClass getBignumClass() {
return bignumClass;
}

0 comments on commit 409925e

Please sign in to comment.