ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-dev:50527] [Ruby trunk Bug#14726] wrong message when superclass is not a Class
       [not found] <redmine.issue-14726.20180501014916@ruby-lang.org>
@ 2018-05-01  1:49 ` usa
  2018-05-01  2:31 ` [ruby-dev:50529] " yugui
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: usa @ 2018-05-01  1:49 UTC (permalink / raw)
  To: ruby-dev

Issue #14726 has been reported by usa (Usaku NAKAMURA).

----------------------------------------
Bug #14726: wrong message when superclass is not a Class
https://bugs.ruby-lang.org/issues/14726

* Author: usa (Usaku NAKAMURA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.0dev (2018-05-01 trunk 63310) [x64-mswin64_140]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
クラス定義の際に親クラスとして`Class`でないものを与えると`TypeError`になりますが、その際にエラーメッセージに与えられたもののクラス名が表示されるため、メッセージだけ見ると何が間違ってるのかわけがわからなくなっています。

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

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

```diff
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);
```




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-dev:50529] [Ruby trunk Bug#14726] wrong message when superclass is not a Class
       [not found] <redmine.issue-14726.20180501014916@ruby-lang.org>
  2018-05-01  1:49 ` [ruby-dev:50527] [Ruby trunk Bug#14726] wrong message when superclass is not a Class usa
@ 2018-05-01  2:31 ` yugui
  2018-05-01  2:34 ` [ruby-dev:50530] " yugui
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: yugui @ 2018-05-01  2:31 UTC (permalink / raw)
  To: ruby-dev

Issue #14726 has been updated by yugui (Yuki Sonoda).


どちらかというと元の仕様のほうに賛成で、これはバグではないという認識です。Classオブジェクトを期待していたのにC1オブジェクトが来たというのはどちらも `super` の属するクラスの話をしていて、そのパッチよりもバランスが取れています。
このエラーメッセージが分かりにくいのは冠詞が抜けているからではないでしょうか。

```diff
-    rb_raise(rb_eTypeError, "superclass must be a Class (%"PRIsVALUE" given)",
+    rb_raise(rb_eTypeError, "superclass must be a Class (given a %"PRIsVALUE")",
```


----------------------------------------
Bug #14726: wrong message when superclass is not a Class
https://bugs.ruby-lang.org/issues/14726#change-71745

* Author: usa (Usaku NAKAMURA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.0dev (2018-05-01 trunk 63310) [x64-mswin64_140]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
クラス定義の際に親クラスとして`Class`でないものを与えると`TypeError`になりますが、その際にエラーメッセージに与えられたもののクラス名が表示されるため、メッセージだけ見ると何が間違ってるのかわけがわからなくなっています。

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

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

```diff
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);
```




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-dev:50530] [Ruby trunk Bug#14726] wrong message when superclass is not a Class
       [not found] <redmine.issue-14726.20180501014916@ruby-lang.org>
  2018-05-01  1:49 ` [ruby-dev:50527] [Ruby trunk Bug#14726] wrong message when superclass is not a Class usa
  2018-05-01  2:31 ` [ruby-dev:50529] " yugui
@ 2018-05-01  2:34 ` yugui
  2018-05-01  3:58 ` [ruby-dev:50533] " usa
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: yugui @ 2018-05-01  2:34 UTC (permalink / raw)
  To: ruby-dev

Issue #14726 has been updated by yugui (Yuki Sonoda).


ああ、補足ですが、`super` の属するクラスではなく `super` の文字列表現を表示するというパッチの案に対しては、誤ってmoduleを渡した場合が心配です。
そのmoduleをクラスだと思い込んでいると却って分かりづらいのではないでしょうか。

----------------------------------------
Bug #14726: wrong message when superclass is not a Class
https://bugs.ruby-lang.org/issues/14726#change-71747

* Author: usa (Usaku NAKAMURA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.0dev (2018-05-01 trunk 63310) [x64-mswin64_140]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
クラス定義の際に親クラスとして`Class`でないものを与えると`TypeError`になりますが、その際にエラーメッセージに与えられたもののクラス名が表示されるため、メッセージだけ見ると何が間違ってるのかわけがわからなくなっています。

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

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

```diff
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);
```




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-dev:50533] [Ruby trunk Bug#14726] wrong message when superclass is not a Class
       [not found] <redmine.issue-14726.20180501014916@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2018-05-01  2:34 ` [ruby-dev:50530] " yugui
@ 2018-05-01  3:58 ` usa
  2018-05-01  4:05 ` [ruby-dev:50534] " usa
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: usa @ 2018-05-01  3:58 UTC (permalink / raw)
  To: ruby-dev

Issue #14726 has been updated by usa (Usaku NAKAMURA).


なるほど、確かに冠詞があればインスタンスが来たとわかるのでいいかも。
私の案だとモジュールが来た時わかりにくいというのも納得です。

----------------------------------------
Bug #14726: wrong message when superclass is not a Class
https://bugs.ruby-lang.org/issues/14726#change-71755

* Author: usa (Usaku NAKAMURA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.0dev (2018-05-01 trunk 63310) [x64-mswin64_140]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
クラス定義の際に親クラスとして`Class`でないものを与えると`TypeError`になりますが、その際にエラーメッセージに与えられたもののクラス名が表示されるため、メッセージだけ見ると何が間違ってるのかわけがわからなくなっています。

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

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

```diff
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);
```




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-dev:50534] [Ruby trunk Bug#14726] wrong message when superclass is not a Class
       [not found] <redmine.issue-14726.20180501014916@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2018-05-01  3:58 ` [ruby-dev:50533] " usa
@ 2018-05-01  4:05 ` usa
  2018-05-01  4:27 ` [ruby-dev:50535] " yugui
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: usa @ 2018-05-01  4:05 UTC (permalink / raw)
  To: ruby-dev

Issue #14726 has been updated by usa (Usaku NAKAMURA).


……で、不定冠詞を付ける場合、例えば`Integer`のインスタンスが来たら`an`にしないといけないのでは、という問題が……。

----------------------------------------
Bug #14726: wrong message when superclass is not a Class
https://bugs.ruby-lang.org/issues/14726#change-71756

* Author: usa (Usaku NAKAMURA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.0dev (2018-05-01 trunk 63310) [x64-mswin64_140]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
クラス定義の際に親クラスとして`Class`でないものを与えると`TypeError`になりますが、その際にエラーメッセージに与えられたもののクラス名が表示されるため、メッセージだけ見ると何が間違ってるのかわけがわからなくなっています。

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

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

```diff
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);
```




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-dev:50535] [Ruby trunk Bug#14726] wrong message when superclass is not a Class
       [not found] <redmine.issue-14726.20180501014916@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2018-05-01  4:05 ` [ruby-dev:50534] " usa
@ 2018-05-01  4:27 ` yugui
  2018-05-07  6:03 ` [ruby-dev:50536] " mame
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: yugui @ 2018-05-01  4:27 UTC (permalink / raw)
  To: ruby-dev

Issue #14726 has been updated by yugui (Yuki Sonoda).


なるほど、それは気づきませんでした。すると、こうでしょうか。

```c
rb_raise(rb_eTypeError, "superclass must be a Class (given a(n) %"PRIsVALUE")",
```

https://en.wiktionary.org/wiki/a(n)

----------------------------------------
Bug #14726: wrong message when superclass is not a Class
https://bugs.ruby-lang.org/issues/14726#change-71757

* Author: usa (Usaku NAKAMURA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.0dev (2018-05-01 trunk 63310) [x64-mswin64_140]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
クラス定義の際に親クラスとして`Class`でないものを与えると`TypeError`になりますが、その際にエラーメッセージに与えられたもののクラス名が表示されるため、メッセージだけ見ると何が間違ってるのかわけがわからなくなっています。

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

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

```diff
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);
```




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-dev:50536] [Ruby trunk Bug#14726] wrong message when superclass is not a Class
       [not found] <redmine.issue-14726.20180501014916@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2018-05-01  4:27 ` [ruby-dev:50535] " yugui
@ 2018-05-07  6:03 ` mame
  2018-05-07  6:29 ` [ruby-dev:50537] " duerst
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: mame @ 2018-05-07  6:03 UTC (permalink / raw)
  To: ruby-dev

Issue #14726 has been updated by mame (Yusuke Endoh).


くだらないコメントです。英語がわかりませんが、"given a XXX" の語順は変な気がします。"a XXX given" でいいような?

----------------------------------------
Bug #14726: wrong message when superclass is not a Class
https://bugs.ruby-lang.org/issues/14726#change-71885

* Author: usa (Usaku NAKAMURA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.0dev (2018-05-01 trunk 63310) [x64-mswin64_140]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
クラス定義の際に親クラスとして`Class`でないものを与えると`TypeError`になりますが、その際にエラーメッセージに与えられたもののクラス名が表示されるため、メッセージだけ見ると何が間違ってるのかわけがわからなくなっています。

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

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

```diff
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);
```




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-dev:50537] [Ruby trunk Bug#14726] wrong message when superclass is not a Class
       [not found] <redmine.issue-14726.20180501014916@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2018-05-07  6:03 ` [ruby-dev:50536] " mame
@ 2018-05-07  6:29 ` duerst
  2018-05-07  6:39 ` [ruby-dev:50538] " mame
  2019-10-17 22:49 ` [ruby-dev:50849] [Ruby master " merch-redmine
  9 siblings, 0 replies; 10+ messages in thread
From: duerst @ 2018-05-07  6:29 UTC (permalink / raw)
  To: ruby-dev

Issue #14726 has been updated by duerst (Martin Dürst).


mame (Yusuke Endoh) wrote:
> くだらないコメントです。英語がわかりませんが、"given a XXX" の語順は変な気がします。"a XXX given" でいいような?

念のためぐたいれいをみたいですが、"given a(n) XXX" は大丈夫かもしれません。"was XXX" はもうちょっと短くて簡単なのかもしれません。

----------------------------------------
Bug #14726: wrong message when superclass is not a Class
https://bugs.ruby-lang.org/issues/14726#change-71886

* Author: usa (Usaku NAKAMURA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.0dev (2018-05-01 trunk 63310) [x64-mswin64_140]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
クラス定義の際に親クラスとして`Class`でないものを与えると`TypeError`になりますが、その際にエラーメッセージに与えられたもののクラス名が表示されるため、メッセージだけ見ると何が間違ってるのかわけがわからなくなっています。

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

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

```diff
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);
```




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-dev:50538] [Ruby trunk Bug#14726] wrong message when superclass is not a Class
       [not found] <redmine.issue-14726.20180501014916@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2018-05-07  6:29 ` [ruby-dev:50537] " duerst
@ 2018-05-07  6:39 ` mame
  2019-10-17 22:49 ` [ruby-dev:50849] [Ruby master " merch-redmine
  9 siblings, 0 replies; 10+ messages in thread
From: mame @ 2018-05-07  6:39 UTC (permalink / raw)
  To: ruby-dev

Issue #14726 has been updated by mame (Yusuke Endoh).


duerst (Martin Dürst) wrote:
> mame (Yusuke Endoh) wrote:
> > くだらないコメントです。英語がわかりませんが、"given a XXX" の語順は変な気がします。"a XXX given" でいいような?
> 
> 念のためぐたいれいをみたいですが、"given a(n) XXX" は大丈夫かもしれません。"was XXX" はもうちょっと短くて簡単なのかもしれません。

具体例は `TypeError (superclass must be a Class (given a(n) C1))` になると思います。(カッコが 3 重でくどいですね)

----------------------------------------
Bug #14726: wrong message when superclass is not a Class
https://bugs.ruby-lang.org/issues/14726#change-71888

* Author: usa (Usaku NAKAMURA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.0dev (2018-05-01 trunk 63310) [x64-mswin64_140]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
クラス定義の際に親クラスとして`Class`でないものを与えると`TypeError`になりますが、その際にエラーメッセージに与えられたもののクラス名が表示されるため、メッセージだけ見ると何が間違ってるのかわけがわからなくなっています。

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

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

```diff
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);
```




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-dev:50849] [Ruby master Bug#14726] wrong message when superclass is not a Class
       [not found] <redmine.issue-14726.20180501014916@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2018-05-07  6:39 ` [ruby-dev:50538] " mame
@ 2019-10-17 22:49 ` merch-redmine
  9 siblings, 0 replies; 10+ messages in thread
From: merch-redmine @ 2019-10-17 22:49 UTC (permalink / raw)
  To: ruby-dev

Issue #14726 has been updated by jeremyevans0 (Jeremy Evans).

File subclass-not-class-err-msg-14726.patch added

It looks like this error message has not been changed.  Attached is a patch with a slightly more verbose and descriptive error message:

```ruby
class C1; end
C2 < C1.new; end
# TypeError (superclass must be an instance of Class (given an instance of C1))
```

I think this avoids the a/an/a(n) issue, and it helps users learn that classes are instances of `Class`, which is an important part of understanding Ruby's object model.  Thoughts?

----------------------------------------
Bug #14726: wrong message when superclass is not a Class
https://bugs.ruby-lang.org/issues/14726#change-82140

* Author: usa (Usaku NAKAMURA)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.0dev (2018-05-01 trunk 63310) [x64-mswin64_140]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
クラス定義の際に親クラスとして`Class`でないものを与えると`TypeError`になりますが、その際にエラーメッセージに与えられたもののクラス名が表示されるため、メッセージだけ見ると何が間違ってるのかわけがわからなくなっています。

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

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

```diff
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)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-10-17 22:49 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-14726.20180501014916@ruby-lang.org>
2018-05-01  1:49 ` [ruby-dev:50527] [Ruby trunk Bug#14726] wrong message when superclass is not a Class usa
2018-05-01  2:31 ` [ruby-dev:50529] " yugui
2018-05-01  2:34 ` [ruby-dev:50530] " yugui
2018-05-01  3:58 ` [ruby-dev:50533] " usa
2018-05-01  4:05 ` [ruby-dev:50534] " usa
2018-05-01  4:27 ` [ruby-dev:50535] " yugui
2018-05-07  6:03 ` [ruby-dev:50536] " mame
2018-05-07  6:29 ` [ruby-dev:50537] " duerst
2018-05-07  6:39 ` [ruby-dev:50538] " mame
2019-10-17 22:49 ` [ruby-dev:50849] [Ruby master " merch-redmine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).