Skip to content

Commit

Permalink
Inherited constants are ignored when defining a new class
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 17, 2013
1 parent e7d9f16 commit 48f622d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
14 changes: 9 additions & 5 deletions corelib/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
const_scope.constants = [];

if (id) {
klass._orig_scope = base;
base[id] = base.constructor[id] = klass;
base.constants.push(id);
}
Expand Down Expand Up @@ -109,7 +110,6 @@
* @return [Class] new or existing ruby class
*/
Opal.klass = function(base, superklass, id, constructor) {
var klass;

// If base is an object, use its class
if (!base._isClass) {
Expand All @@ -121,9 +121,10 @@
superklass = RubyObject;
}

var klass = base._scope[id];

// If a constant exists in the scope, then we must use that
if ($hasOwn.call(base._scope, id)) {
klass = base._scope[id];
if ($hasOwn.call(base._scope, id) && klass._orig_scope === base._scope) {

// Make sure the existing constant is a class, or raise error
if (!klass._isClass) {
Expand Down Expand Up @@ -682,10 +683,13 @@

Opal.base = RubyObject;
RubyBasicObject._scope = RubyObject._scope = Opal;
RubyBasicObject._orig_scope = RubyObject._orig_scope = Opal;
Opal.Kernel = RubyObject;

RubyModule._scope= RubyObject._scope;
RubyClass._scope= RubyObject._scope;
RubyModule._scope = RubyObject._scope;
RubyClass._scope = RubyObject._scope;
RubyModule._orig_scope = RubyObject._orig_scope;
RubyClass._orig_scope = RubyObject._orig_scope;

RubyObject._proto.toString = function() {
return this.$to_s();
Expand Down
1 change: 1 addition & 0 deletions spec/filters/bugs/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
fails "A class definition raises TypeError if the constant qualifying the class is nil"
fails "A class definition raises TypeError if any constant qualifying the class is not a Module"
fails "A class definition allows using self as the superclass if self is a class"
fails "A class definition raises TypeError if constant given as class name exists and is not a Module"
fails "A class definition raises a TypeError if inheriting from a metaclass"
fails "A class definition extending an object (sclass) raises a TypeError when trying to extend numbers"
fails "A class definition extending an object (sclass) allows accessing the block of the original scope"
Expand Down

0 comments on commit 48f622d

Please sign in to comment.