Project

General

Profile

Actions

Bug #14726

closed

wrong message when superclass is not a Class

Added by usa (Usaku NAKAMURA) over 6 years ago. Updated about 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.0dev (2018-05-01 trunk 63310) [x64-mswin64_140]
[ruby-dev:50527]
Tags:

Description

クラス定義の際に親クラスとしてClassでないものを与えるとTypeErrorになりますが、その際にエラーメッセージに与えられたもののクラス名が表示されるため、メッセージだけ見ると何が間違ってるのかわけがわからなくなっています。

class C1; end
class C2 < C1.new; end #=> TypeError (superclass must be a Class (C1 given))

ここはクラス名ではなく与えられたオブジェクトそのものを表示すべきではないでしょうか?

Index: class.c
===================================================================
--- class.c	(revision 63310)
+++ class.c	(working copy)
@@ -221,7 +221,7 @@
 {
     if (!RB_TYPE_P(super, T_CLASS)) {
 	rb_raise(rb_eTypeError, "superclass must be a Class (%"PRIsVALUE" given)",
-		 rb_obj_class(super));
+		 super);
     }
     if (RBASIC(super)->flags & FL_SINGLETON) {
 	rb_raise(rb_eTypeError, "can't make subclass of singleton class");
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 63310)
+++ vm_insnhelper.c	(working copy)
@@ -3150,7 +3150,7 @@
     if (VM_DEFINECLASS_HAS_SUPERCLASS_P(flags) && !RB_TYPE_P(super, T_CLASS)) {
 	rb_raise(rb_eTypeError,
 		 "superclass must be a Class (%"PRIsVALUE" given)",
-		 rb_obj_class(super));
+		 super);
     }
 
     vm_check_if_namespace(cbase);

Files

subclass-not-class-err-msg-14726.patch (2.36 KB) subclass-not-class-err-msg-14726.patch jeremyevans0 (Jeremy Evans), 10/17/2019 10:44 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0