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=-4.1 required=3.0 tests=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 B6A961F463 for ; Wed, 11 Sep 2019 15:36:27 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id A91AC120A0E; Thu, 12 Sep 2019 00:36:17 +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 311D91209B1 for ; Thu, 12 Sep 2019 00:36:14 +0900 (JST) Received: by filter0094p3las1.sendgrid.net with SMTP id filter0094p3las1-32764-5D791473-3E 2019-09-11 15:36:19.269000984 +0000 UTC m=+78531.619631204 Received: from herokuapp.com (unknown [3.95.23.246]) by ismtpd0049p1mdw1.sendgrid.net (SG) with ESMTP id 7iP7cP4pRQ-OQ3245jKEnA for ; Wed, 11 Sep 2019 15:36:19.120 +0000 (UTC) Date: Wed, 11 Sep 2019 15:36:19 +0000 (UTC) From: daniel@dan42.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70458 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16157 X-Redmine-Issue-Author: Dan0042 X-Redmine-Sender: Dan0042 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?8sy4RigFvRTdBfCVJrT9zb2J88PC92TMQwdNgaWYaq4rZyWE45dj2Xg+ixYI74?= =?us-ascii?Q?Afax3pLsFBXlSCbtfGwRoYgiUqKs0D8fUJT01ll?= =?us-ascii?Q?Z+LxP7LUh=2F0FnaJAKjUQ3WEnOL7NWx88KdVzldE?= =?us-ascii?Q?+3VJlakRdbNcxG1PHLgsEMXSa8Pp8jgOxGkKcyY?= =?us-ascii?Q?3DFXdjsvNPMq=2Fo7Q4z+eonyBfNIrV57XulQ=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 94904 Subject: [ruby-core:94904] [Ruby master Misc#16157] What is the correct and *portable* way to do generic delegation? 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 #16157 has been updated by Dan0042 (Daniel DeLorme). > Prior to the keyword argument separation branch merge, it was not even possible for a C method to tell if it was called with keywords or called with a positional hash. That's the same situation as ruby methods used to be in. So *theoretically* C methods are susceptible to the same problem. But very very few C methods have a signature that would allow to trigger the bug. However, feast your eyes on the behavior of `warn()` (on ruby master) ``` >> warn({x:1}) ArgumentError (unknown keyword: :x) >> warn({x:1}, uplevel:0) (irb):4: warning: {:x=>1} >> warn({x:1}, **{}) >> warn({x:1}, {}) >> warn({x:1}, {}, {}) {:x=>1} >> warn({x:1}, {}, {}, {}) {:x=>1} {} >> warn({x:1}, {y:2}, {}) ArgumentError (unknown keyword: :y) >> warn({x:1}, {y:2}, {}, {}) {:x=>1} {:y=>2} ``` Of course this is all *extremely* unconventional usage and doesn't really deserve a fix. But I thought it was weird/interesting. > The only time you really need the RUBY_VERSION check is for complete argument delegation to arbitrary methods with arbitrary arguments. For reference, searching for only arbitrary delegation (`send`/`__send__` with `*args`) gives 179 matches in 158 files of 86 gems (not all of which will require kwargs) https://pastebin.com/HX3w5ngK > The only behavior difference is for **{}, which was ignored by the parser in 2.6, and is not likely to appear in production code. Confirmed, not a single appearance in the 679 gems I installed. > However, the changes are necessary to fix the problems with keyword arguments. I still disagree with that, but that's another argument, another story ;-) ---------------------------------------- Misc #16157: What is the correct and *portable* way to do generic delegation? https://bugs.ruby-lang.org/issues/16157#change-81518 * Author: Dan0042 (Daniel DeLorme) * Status: Open * Priority: Normal * Assignee: ---------------------------------------- With the keyword argument changes in 2.7 we must now specify keyword arguments explicitly when doing generic delegation. But this change is not compatible with 2.6, where it adds an empty hash to the argument list of methods that do not need/accept keyword arguments. To illustrate the problem: ```ruby class ProxyWithoutKW < BasicObject def initialize(target) @target = target end def method_missing(*a, &b) @target.send(*a, &b) end end class ProxyWithKW < BasicObject def initialize(target) @target = target end def method_missing(*a, **o, &b) @target.send(*a, **o, &b) end end class Test def args(*a) a end def arg(a) a end def opts(**o) o end end # 2.6 2.7 3.0 ProxyWithoutKW.new(Test.new).args(42) # [42] [42] [42] ok ProxyWithoutKW.new(Test.new).arg(42) # 42 42 42 ok ProxyWithoutKW.new(Test.new).opts(k: 42) # {:k=>42} {:k=>42} +warn [{:k=>42}] incompatible with >= 2.7 ProxyWithKW.new(Test.new).args(42) # [42, {}] [42] [42] incompatible with <= 2.6 ProxyWithKW.new(Test.new).arg(42) # error 42 42 incompatible with <= 2.6 ProxyWithKW.new(Test.new).opts(k: 42) # {:k=>42} {:k=>42} +warn {:k=>42} must ignore warning? cannot use pass_positional_hash in 2.6 ``` I don't know how to solve this, so I'm asking for the **official** correct way to write portable delegation code. And by **portable** I mean code that can be used in gems that target ruby 2.6 and above. -- https://bugs.ruby-lang.org/