ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: merch-redmine@jeremyevans.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:93046] [Ruby trunk Bug#15857] <=> の右辺が <=> を実装していない場合の振る舞い
Date: Tue, 11 Jun 2019 17:18:04 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-78440.20190611171803.b24b0eab67ded858@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15857.20190517104016@ruby-lang.org

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

File complex-real-spaceship-v3.patch added

shuujii (Shuji KOBAYASHI) wrote:
> @jeremyevans0 Thank you for your comment. About `Complex`, I agree with most of v2 patch, but I have some comments.
> 
> - Should methods from `Comparable` that are currently disabled be enabled?

I don't think so, but I don't have a strong opinion.  If you would like those added, please submit a separate feature request for that.

> - `rb_undef_method(rb_cComplex, "<=>")` is unneeded.
> - `idCmp` can be used instead of `id_spaceship`.

Thank you, I made both of these changes in the attached v3 patch.

> About other than `Complex`, `<=>` of some classes, such as `String` and `Time`, will fail if LHS does not implement `<=>`. It's better to return `nil` in this case too, because whether it's comparable or not and whether LHS implements `<=>` or not is essentially irrelevant, I think.

I agree, but please submit a separate bug report for that as it is unrelated to `Complex#<=>`.

----------------------------------------
Bug #15857: <=> の右辺が <=> を実装していない場合の振る舞い
https://bugs.ruby-lang.org/issues/15857#change-78440

* Author: shuujii (Shuji KOBAYASHI)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
`<=>` の右辺が `<=>` を実装していないとき、`nil` が返却される場合と例外が発生する場合があり一貫性がないように思えるのですが、意図的でしょうか。

```ruby
  0 <=> 0i               #=> NoMethodError (undefined method `<=>' for (0+0i):Complex)
  0 <=> BasicObject.new  #=> nil
 :a <=> 0i               #=> nil
"a" <=> 0i               #=> NoMethodError (undefined method `<=>' for (0+0i):Complex)

```

なお、`0 <=> 0i` に関しては、`0 == 0i` は `true` になるのでそれとも一貫性がないように思えるのもやや気になりました。

---Files--------------------------------
complex-real-spaceship.patch (8.75 KB)
complex-real-spaceship-v2.patch (8.08 KB)
complex-real-spaceship-v3.patch (7.79 KB)


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

  parent reply	other threads:[~2019-06-11 17:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-15857.20190517104016@ruby-lang.org>
2019-05-17 10:40 ` [ruby-core:92694] [Ruby trunk Bug#15857] <=> の右辺が <=> を実装していない場合の振る舞い shuujii
2019-06-05  4:55 ` [ruby-core:92970] " merch-redmine
2019-06-05  8:33 ` [ruby-core:92975] " sawadatsuyoshi
2019-06-06  2:33 ` [ruby-core:92993] " merch-redmine
2019-06-08 12:17 ` [ruby-core:93023] " eregontp
2019-06-11 14:09 ` [ruby-core:93044] " shuujii
2019-06-11 17:18 ` merch-redmine [this message]
2019-06-14  1:02 ` [ruby-core:93119] " shuujii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-78440.20190611171803.b24b0eab67ded858@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).