From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.9 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id D6DA91F4C0 for ; Tue, 15 Oct 2019 14:34:34 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id AD1381209FF; Tue, 15 Oct 2019 23:34:21 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id BB3611209FC for ; Tue, 15 Oct 2019 23:34:18 +0900 (JST) Received: by filter0178p3mdw1.sendgrid.net with SMTP id filter0178p3mdw1-27722-5DA5D8E7-158 2019-10-15 14:34:15.945075034 +0000 UTC m=+490508.908531736 Received: from herokuapp.com (unknown [52.91.31.13]) by ismtpd0048p1mdw1.sendgrid.net (SG) with ESMTP id EZiykWwERlCIU7-3yB3w4g for ; Tue, 15 Oct 2019 14:34:15.841 +0000 (UTC) Date: Tue, 15 Oct 2019 14:34:16 +0000 (UTC) From: merch-redmine@jeremyevans.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70922 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15608 X-Redmine-Issue-Author: Eregon X-Redmine-Sender: jeremyevans0 X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?RVE3t853K5scBhbmJHUzZTFFeVC=2FZSUmHZ0Dc+26wcEi2CTgsF1oz0wTSSxGGN?= =?us-ascii?Q?BIwOLYIOLlu7qoaexuCF7y0BNK=2FDVj9IIdT5VM5?= =?us-ascii?Q?OougDH1E0t4Aelbly8fU45i0rC12qB4dAX02B=2FH?= =?us-ascii?Q?aqS5Zd4YSDL6X=2FjVO+q4mWH=2FZJDO+1Ir0Q8wo9M?= =?us-ascii?Q?tFw=2FyLljvdUpBmorFcCiqKayrD7FIlcVVyQ=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95334 Subject: [ruby-core:95334] [Ruby master Bug#15608] What should be the correct output for Method#inspect with singleton methods? X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #15608 has been updated by jeremyevans0 (Jeremy Evans). Eregon (Benoit Daloze) wrote: > What tests does it break, could you copy the output? I didn't keep the output. From a brief analysis, it appeared to be to be tests that you wouldn't want to break. Using `data->iclass` instead of `data->klass` results in `C#foo` instead of `D(C)#foo` for `D.new.method(:foo)`. ---------------------------------------- Bug #15608: What should be the correct output for Method#inspect with singleton methods? https://bugs.ruby-lang.org/issues/15608#change-82042 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux] * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- bug.rb: ```ruby class C def foo end end obj = C.new class << obj alias bar foo end p obj.method(:foo).owner p obj.method(:foo) raise unless obj.method(:foo).owner == C p obj.method(:bar).owner p obj.method(:bar) raise unless obj.method(:bar).owner == obj.singleton_class ``` ``` $ chruby 2.0.0 $ ruby -v bug.rb ruby 2.0.0p648 (2015-12-16) [x86_64-linux] C # #> # $ chruby 2.3.8 $ ruby -v bug.rb ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-linux] C # #> #.bar(foo)> $ chruby 2.4.5 $ ruby -v bug.rb ruby 2.4.5p335 (2018-10-18 revision 65137) [x86_64-linux] C #.foo> #> #.bar(foo)> Same for 2.5.3 and 2.6.1 ``` I think Method#inspect should show on which Module the method is defined (`Method#owner`), and only singleton methods should be shown as `receiver.method`, so: ``` C # #> #.bar(foo)> ``` Which only Ruby 2.3 does interestingly. --- What's the meaning of the `C1(C2)` notation? It seems to show `"#{receiver.class}(#{owner})` or `"#{receiver.singleton_class if receiver has a sclass}` depending on the version: ```ruby class D < C end d = D.new p d.method(:foo) d.singleton_class p d.method(:foo) ``` ``` 2.0-2.3: # # 2.4-2.6: # #.foo> ``` I think the Ruby 2.4+ behavior is confusing and incorrect here, the object shouldn't be shown if it's not a singleton method, and Method#inspect shouldn't change for a given method. Do you agree what I describe should be the correct behavior? Can we fix it then? ---Files-------------------------------- method-inspect-15608.patch (2.31 KB) -- https://bugs.ruby-lang.org/