[前][次][番号順一覧][スレッド一覧]

ruby-changes:63601

From: Jeremy <ko1@a...>
Date: Sat, 14 Nov 2020 00:06:41 +0900 (JST)
Subject: [ruby-changes:63601] ce9beb9d20 (master): Improve error message when subclassing non-Class

https://git.ruby-lang.org/ruby.git/commit/?id=ce9beb9d20

From ce9beb9d20187c861462282460b998684759e5e7 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@j...>
Date: Sat, 18 Jul 2020 08:18:39 -0700
Subject: Improve error message when subclassing non-Class

Fixes [Bug #14726]

diff --git a/class.c b/class.c
index 4b8130d..7cc087f 100644
--- a/class.c
+++ b/class.c
@@ -227,7 +227,7 @@ void https://github.com/ruby/ruby/blob/trunk/class.c#L227
 rb_check_inheritable(VALUE super)
 {
     if (!RB_TYPE_P(super, T_CLASS)) {
-	rb_raise(rb_eTypeError, "superclass must be a Class (%"PRIsVALUE" given)",
+        rb_raise(rb_eTypeError, "superclass must be an instance of Class (given an instance of %"PRIsVALUE")",
 		 rb_obj_class(super));
     }
     if (RBASIC(super)->flags & FL_SINGLETON) {
diff --git a/spec/ruby/core/class/new_spec.rb b/spec/ruby/core/class/new_spec.rb
index f863766..93152a8 100644
--- a/spec/ruby/core/class/new_spec.rb
+++ b/spec/ruby/core/class/new_spec.rb
@@ -95,7 +95,7 @@ describe "Class.new" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/class/new_spec.rb#L95
   end
 
   it "raises a TypeError when given a non-Class" do
-    error_msg = /superclass must be a Class/
+    error_msg = /superclass must be a.*Class/
     -> { Class.new("")              }.should raise_error(TypeError, error_msg)
     -> { Class.new(1)               }.should raise_error(TypeError, error_msg)
     -> { Class.new(:symbol)         }.should raise_error(TypeError, error_msg)
diff --git a/spec/ruby/language/class_spec.rb b/spec/ruby/language/class_spec.rb
index fa30e22..83db164 100644
--- a/spec/ruby/language/class_spec.rb
+++ b/spec/ruby/language/class_spec.rb
@@ -286,7 +286,7 @@ describe "A class definition extending an object (sclass)" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/language/class_spec.rb#L286
   end
 
   it "raises a TypeError when trying to extend non-Class" do
-    error_msg = /superclass must be a Class/
+    error_msg = /superclass must be a.* Class/
     -> { class TestClass < "";              end }.should raise_error(TypeError, error_msg)
     -> { class TestClass < 1;               end }.should raise_error(TypeError, error_msg)
     -> { class TestClass < :symbol;         end }.should raise_error(TypeError, error_msg)
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 74e992a..2fa9637 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -4068,7 +4068,7 @@ vm_define_class(ID id, rb_num_t flags, VALUE cbase, VALUE super) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L4068
 
     if (VM_DEFINECLASS_HAS_SUPERCLASS_P(flags) && !RB_TYPE_P(super, T_CLASS)) {
 	rb_raise(rb_eTypeError,
-		 "superclass must be a Class (%"PRIsVALUE" given)",
+                 "superclass must be an instance of Class (given an instance of %"PRIsVALUE")",
 		 rb_obj_class(super));
     }
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]