Skip to content

Commit

Permalink
Merge pull request #677 from krekoten/class_new
Browse files Browse the repository at this point in the history
Class#new superclass check and naming
  • Loading branch information
alex committed May 3, 2013
2 parents d7b5f06 + 476051e commit 43639ba
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
8 changes: 0 additions & 8 deletions spec/tags/core/class/new_tags.txt

This file was deleted.

3 changes: 1 addition & 2 deletions spec/tags/core/module/name_tags.txt
@@ -1,7 +1,6 @@
fails:Module#name is nil for a nested module created with the module keyword
fails:Module#name is set when assigning to a constant
fails:Module#name is not modified when assigning to a new constant after it has been accessed
fails:Module#name is set with a conditional assignment to a nested constant
fails:Module#name is set with a conditional assignment to a constant
fails:Module#name preserves the encoding in which the class was defined
fails:Module#name is set when the anonymous outer module name is set
fails:Module#name is nil when assigned to a constant in an anonymous module
2 changes: 2 additions & 0 deletions topaz/interpreter.py
Expand Up @@ -202,6 +202,8 @@ def STORE_CONSTANT(self, space, bytecode, frame, pc, idx):
w_value = frame.pop()
w_scope = frame.pop()
space.set_const(w_scope, name, w_value)
if isinstance(w_value, W_ModuleObject) and w_value.name is None:
w_value.name = space.buildname(name, w_scope)
frame.push(w_value)

def DEFINED_CONSTANT(self, space, bytecode, frame, pc, idx):
Expand Down
11 changes: 10 additions & 1 deletion topaz/objects/classobject.py
Expand Up @@ -84,7 +84,16 @@ def method_removed(self, space, w_name):
@classdef.singleton_method("allocate")
def singleton_method_allocate(self, space, w_superclass=None):
if w_superclass is not None:
assert isinstance(w_superclass, W_ClassObject)
if not isinstance(w_superclass, W_ClassObject):
raise space.error(
space.w_TypeError,
"superclass must be a Class (%s given)" % space.obj_to_s(space.getclass(w_superclass))
)
if w_superclass.is_singleton:
raise space.error(
space.w_TypeError,
"can't make subclass of singleton class"
)
else:
w_superclass = space.w_object
return space.newclass(None, w_superclass)
Expand Down

0 comments on commit 43639ba

Please sign in to comment.