summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/class.c3
-rw-r--r--test/t/class.rb10
2 files changed, 6 insertions, 7 deletions
diff --git a/src/class.c b/src/class.c
index f446c56bc..f94f9a933 100644
--- a/src/class.c
+++ b/src/class.c
@@ -1047,6 +1047,9 @@ mrb_instance_new(mrb_state *mrb, mrb_value cv)
mrb_value *argv;
int argc;
+ if (c->tt == MRB_TT_SCLASS)
+ mrb_raise(mrb, E_TYPE_ERROR, "can't create instance of singleton class");
+
if (ttype == 0) ttype = MRB_TT_OBJECT;
o = (struct RObject*)mrb_obj_alloc(mrb, ttype, c);
obj = mrb_obj_value(o);
diff --git a/test/t/class.rb b/test/t/class.rb
index 13845a49f..c558c6437 100644
--- a/test/t/class.rb
+++ b/test/t/class.rb
@@ -30,13 +30,9 @@ assert('Class#initialize_copy', '15.2.3.3.2') do
end
assert('Class#new', '15.2.3.3.3') do
- # at the moment no exception on singleton class
- #e1 = nil
- #begin
- # class1 = e1.singleton_class.new
- #rescue => e1
- # e2 = e1
- #end
+ assert_raise(TypeError, 'Singleton should raise TypeError') do
+ "a".singleton_class.new
+ end
class TestClass
def initialize args, &block