Skip to content

Commit

Permalink
[Truffle] Use a stronger check for class identity.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Dec 29, 2014
1 parent 41bcacf commit 409925e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,10 @@ public RubyClass getArrayClass() {
return arrayClass;
}

public RubyClass getBasicObjectClass() {
return basicObjectClass;
}

public RubyClass getBignumClass() {
return bignumClass;
}
Expand Down

0 comments on commit 409925e

Please sign in to comment.