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.0 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 5BF751F463 for ; Tue, 3 Dec 2019 08:57:27 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 6F533120A2E; Tue, 3 Dec 2019 17:57:14 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 9EC57120A26 for ; Tue, 3 Dec 2019 17:57:12 +0900 (JST) Received: by filter0154p3mdw1.sendgrid.net with SMTP id filter0154p3mdw1-9590-5DE6236D-F 2019-12-03 08:57:17.802605453 +0000 UTC m=+1155730.863274198 Received: from herokuapp.com (unknown [18.212.157.225]) by ismtpd0096p1mdw1.sendgrid.net (SG) with ESMTP id xfG52_-eT3aOjVZXbxSrHw for ; Tue, 03 Dec 2019 08:57:17.708 +0000 (UTC) Date: Tue, 03 Dec 2019 08:57:17 +0000 (UTC) From: naruse@airemix.jp Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 71709 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 13083 X-Redmine-Issue-Author: kachick X-Redmine-Sender: naruse 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?UqoG4vcRhHM9V1I4f4J7DhjzUfTg+8muXbMD6UD+LVTLBFM2xgE2WTOdwjpw7j?= =?us-ascii?Q?KQjR9NybA1sy5jexQ1NJPZCWeLqba8QNYEU0Ois?= =?us-ascii?Q?A1PiRil+gAEM=2FU=2FKvEjRbbZ3IhQ+x4GWOyoes5y?= =?us-ascii?Q?SU36qkWIY+qeIKOGOlpurjoB6HJx6eTOYklBGYt?= =?us-ascii?Q?mEEuWms9BhmNXmBdT5Suj+rTfbjgyLVrp7A=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 96068 Subject: [ruby-core:96068] [Ruby master Feature#13083] Regexp#{match, match?} with a nil argument are deprecated and will raise a TypeError in Ruby 3.0 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 #13083 has been updated by naruse (Yui NARUSE). Eregon (Benoit Daloze) wrote: > > I believe many of us have got used to the original behavior, that is, methods of a Regexp object work permissively and accept nil, and we know we've migrated many pieces of code from `/re/ =~ nilable` / `/re/ === nilable` to `/re/.match?(nilable)` for the sake of performance and readability just as shugo said above. > > > > Can't we reconsider this? Or we'll be doomed to back out all those changes we believed to improve performance. > > `nilable&.match?(/re/)` would be an easy way to rewrite those cases, no? > > @matz and others: what do you think, should we make `Regexp#{match,match?}` consistent and not accept `nil` or accept them as special-case to match the =~ and === operators? I also received the same feedback from Rails people. `nilable&.match?(/re/)` sounds a reasonable option, but why do we provide a such pitfall? ---------------------------------------- Feature #13083: Regexp#{match,match?} with a nil argument are deprecated and will raise a TypeError in Ruby 3.0 https://bugs.ruby-lang.org/issues/13083#change-82917 * Author: kachick (Kenichi Kamiya) * Status: Open * Priority: Normal * Assignee: * Target version: 2.7 ---------------------------------------- Just for consistency * patch: https://github.com/ruby/ruby/pull/1506 * spec: https://github.com/ruby/spec/pull/380 Currently behaves as ( ruby --version: ruby 2.5.0dev (2016-12-28 trunk 57228) [x86_64-darwin16] ) ~~~ ruby 'string'.__send__(:=~, nil) #=> nil 'string'.match(nil) #=> TypeError: wrong argument type nil (expected Regexp) 'string'.match?(nil) #=> TypeError: wrong argument type nil (expected Regexp) :symbol.__send__(:=~, nil) #=> nil :symbol.match(nil) #=> TypeError: wrong argument type nil (expected Regexp) :symbol.match?(nil) #=> TypeError: wrong argument type nil (expected Regexp) /regex/.__send__(:=~, nil) #=> nil /regex/.match(nil) #=> nil /regex/.match?(nil) #=> false ~~~ Expected to ~~~ruby 'string'.__send__(:=~, nil) #=> nil 'string'.match(nil) #=> nil 'string'.match?(nil) #=> false :symbol.__send__(:=~, nil) #=> nil :symbol.match(nil) #=> nil :symbol.match?(nil) #=> false /regex/.__send__(:=~, nil) #=> nil /regex/.match(nil) #=> nil /regex/.match?(nil) #=> false ~~~ -- https://bugs.ruby-lang.org/