From a9087ca645893e887ede474f72d992289799c240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marjan=20Krekoten=27=20=28=D0=9C=D0=B0=D1=80=27=D1=8F?= =?UTF-8?q?=D0=BD=20=D0=9A=D1=80=D0=B5=D0=BA=D0=BE=D1=82=D0=B5=D0=BD=D1=8C?= =?UTF-8?q?=29?= Date: Fri, 3 May 2013 23:54:06 +0300 Subject: [PATCH 1/4] Class.new checks for suoerclass Specs fixed: Class.new - with a block given uses the given block as the class' body - with a block given creates a subclass of the given superclass - with a block given runs the inherited hook after yielding the block - raises a TypeError if passed a metaclass Class#new - invokes #initialize on the new instance with the given args - passes the block to #initialize --- spec/tags/core/class/new_tags.txt | 6 ------ topaz/objects/classobject.py | 11 ++++++++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/spec/tags/core/class/new_tags.txt b/spec/tags/core/class/new_tags.txt index a4d2f2d23..2fb66a472 100644 --- a/spec/tags/core/class/new_tags.txt +++ b/spec/tags/core/class/new_tags.txt @@ -1,8 +1,2 @@ -fails:Class.new with a block given uses the given block as the class' body -fails:Class.new with a block given creates a subclass of the given superclass -fails:Class.new with a block given runs the inherited hook after yielding the block -fails:Class.new raises a TypeError if passed a metaclass fails:Class.new creates a class that can be given a name by assigning it to a constant fails:Class.new -fails:Class#new invokes #initialize on the new instance with the given args -fails:Class#new passes the block to #initialize diff --git a/topaz/objects/classobject.py b/topaz/objects/classobject.py index 706d2372a..4ea599601 100644 --- a/topaz/objects/classobject.py +++ b/topaz/objects/classobject.py @@ -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) From c96b99a225eb1310b30dbc59a780483bc37d1cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marjan=20Krekoten=27=20=28=D0=9C=D0=B0=D1=80=27=D1=8F?= =?UTF-8?q?=D0=BD=20=D0=9A=D1=80=D0=B5=D0=BA=D0=BE=D1=82=D0=B5=D0=BD=D1=8C?= =?UTF-8?q?=29?= Date: Sat, 4 May 2013 00:17:37 +0300 Subject: [PATCH 2/4] Anonymous class gets it's name on assignment Specs fixed: Class.new - creates a class that can be given a name by assigning it to a constant --- spec/tags/core/class/new_tags.txt | 2 -- topaz/interpreter.py | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 spec/tags/core/class/new_tags.txt diff --git a/spec/tags/core/class/new_tags.txt b/spec/tags/core/class/new_tags.txt deleted file mode 100644 index 2fb66a472..000000000 --- a/spec/tags/core/class/new_tags.txt +++ /dev/null @@ -1,2 +0,0 @@ -fails:Class.new creates a class that can be given a name by assigning it to a constant -fails:Class.new diff --git a/topaz/interpreter.py b/topaz/interpreter.py index 2e4314495..ba5b8e34c 100644 --- a/topaz/interpreter.py +++ b/topaz/interpreter.py @@ -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): From 36b648239b49b3b3f9f9e20a1a031856fdbe3ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marjan=20Krekoten=27=20=28=D0=9C=D0=B0=D1=80=27=D1=8F?= =?UTF-8?q?=D0=BD=20=D0=9A=D1=80=D0=B5=D0=BA=D0=BE=D1=82=D0=B5=D0=BD=D1=8C?= =?UTF-8?q?=29?= Date: Sat, 4 May 2013 00:20:54 +0300 Subject: [PATCH 3/4] Anonymous nodule name Specs fixed: Module#name - is set when assigning to a constant - is not modified when assigning to a new constant after it has been accessed --- spec/tags/core/module/name_tags.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/tags/core/module/name_tags.txt b/spec/tags/core/module/name_tags.txt index 34825f028..73349fc77 100644 --- a/spec/tags/core/module/name_tags.txt +++ b/spec/tags/core/module/name_tags.txt @@ -1,6 +1,4 @@ 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 From 476051e8f9cd37514bb75d0ddd2961e2545092f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marjan=20Krekoten=27=20=28=D0=9C=D0=B0=D1=80=27=D1=8F?= =?UTF-8?q?=D0=BD=20=D0=9A=D1=80=D0=B5=D0=BA=D0=BE=D1=82=D0=B5=D0=BD=D1=8C?= =?UTF-8?q?=29?= Date: Sat, 4 May 2013 01:22:38 +0300 Subject: [PATCH 4/4] Tagged failing spec --- spec/tags/core/module/name_tags.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/tags/core/module/name_tags.txt b/spec/tags/core/module/name_tags.txt index 73349fc77..0f3a963ac 100644 --- a/spec/tags/core/module/name_tags.txt +++ b/spec/tags/core/module/name_tags.txt @@ -3,3 +3,4 @@ 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