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 1282C1F4C0 for ; Sat, 12 Oct 2019 23:52:06 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 39F4712092B; Sun, 13 Oct 2019 08:51:57 +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 BE7FF120926 for ; Sun, 13 Oct 2019 08:51:54 +0900 (JST) Received: by filter0099p3las1.sendgrid.net with SMTP id filter0099p3las1-10836-5DA2671F-41 2019-10-12 23:51:59.684493501 +0000 UTC m=+105490.703760728 Received: from herokuapp.com (unknown [3.93.220.99]) by ismtpd0033p1mdw1.sendgrid.net (SG) with ESMTP id 4V1LL68BSRyEVFoJ0BpAfA for ; Sat, 12 Oct 2019 23:51:59.466 +0000 (UTC) Date: Sat, 12 Oct 2019 23:51:59 +0000 (UTC) From: merch-redmine@jeremyevans.net Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70897 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 13446 X-Redmine-Issue-Author: mtsmfm X-Redmine-Issue-Assignee: nobu 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?BI=2Fg=2FZtiMuTjEHJiVuYrQ05CGDmB0Vty+rO8XJT?= =?us-ascii?Q?cPNrX76NDhUge9=2FBRv2wCoKvusdHv3sAef0es=2F6?= =?us-ascii?Q?GLZ9XSroLSxzSpgq2AIIdS=2Fnwn+i1wS7frd+G2+?= =?us-ascii?Q?5aIzV4vpBE=2FXrA80GsF+iwYUh2HBdFdmnzQ=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95310 Subject: [ruby-core:95310] [Ruby master Bug#13446] refinements with prepend for module has strange behavior 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 #13446 has been updated by jeremyevans0 (Jeremy Evans). Fixing this first requires fixing #16242, which allows including a module that uses prepend and is refined. However, the fix for #16242 does not fix the example in this case, as this prepends the included module after the module is included. The reason this is still broken after the fix for #16242 is that a refined module that hasn't been prepended to yet keeps the refined methods in the module's method table. When prepending, the module's method table is moved to the origin iclass, and then the refined methods are moved from the method table to a new method table in the module itself. Unfortunately, that means that if a class has included the module, prepending breaks the refinements, because when the methods are moved from the origin iclass method table to the module method table, they are removed from the method table from the iclass created when the module was included earlier. Fix this by always creating an origin iclass when including a module that has any refinements, even if the refinements are not currently used (see https://github.com/ruby/ruby/pull/2550). I wasn't sure the best way to do that. The approach I choose was to use an object flag. The flag is set on the module when Module#refine is called, and if the flag is present when the module is included in another module or class, an origin iclass is created for the module. ---------------------------------------- Bug #13446: refinements with prepend for module has strange behavior https://bugs.ruby-lang.org/issues/13446#change-81993 * Author: mtsmfm (Fumiaki Matsushima) * Status: Assigned * Priority: Normal * Assignee: nobu (Nobuyoshi Nakada) * Target version: * ruby -v: ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux] * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- ~~~ruby using Module.new { refine Enumerable do alias :orig_sum :sum end } module Enumerable def sum(*args) orig_sum(*args) end end class GenericEnumerable include Enumerable def each end end # GenericEnumerable.new.sum # if we uncomment this line, `GenericEnumerable#sum` will work Enumerable.prepend(Module.new) # if we comment out this line, `GenericEnumerable#sum` will work p GenericEnumerable.new.sum # undefined method `orig_sum' for # (NoMethodError) ~~~ Is this intentional? -- https://bugs.ruby-lang.org/