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-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,UNPARSEABLE_RELAY 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 8A2D11F5AE for ; Wed, 29 Jul 2020 15:19:14 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id E9F8A120A9C; Thu, 30 Jul 2020 00:18:36 +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 D62D5120A98 for ; Thu, 30 Jul 2020 00:18:33 +0900 (JST) Received: by filterdrecv-p3iad2-5b55dcd864-v6r54 with SMTP id filterdrecv-p3iad2-5b55dcd864-v6r54-19-5F219360-3F 2020-07-29 15:18:56.430251551 +0000 UTC m=+2844570.277261380 Received: from herokuapp.com (unknown) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id 6h-70o3sQ8mXp1oDIw1Y7g for ; Wed, 29 Jul 2020 15:18:56.277 +0000 (UTC) Date: Wed, 29 Jul 2020 15:18:56 +0000 (UTC) From: erik@erisc.se Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 75186 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 17058 X-Redmine-Issue-Author: erik_schlyter X-Redmine-Sender: erik_schlyter 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?d34Il5L029XCK+n93cKq6Td=2FRO+om+mDwSTftrpDrXo75evxqbFk4GFDim5H17?= =?us-ascii?Q?47IPCGRuMGyAWb1sgFtx=2FKK6ko3VEIDI1yeGkPJ?= =?us-ascii?Q?IQmPuuUMXn8czrbS0scl8bhO4nigFuHaCJ+ott0?= =?us-ascii?Q?S5RUz9gjkr=2F4LLp+0swFBWxXVCRuD3gHOTElFE0?= =?us-ascii?Q?mM=2FFFcVo339ZenCGQGls7+3xitnunB1qO8A=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 99390 Subject: [ruby-core:99390] [Ruby master Bug#17058] Array#delete_if doesn't change array instantly 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 #17058 has been reported by erik_schlyter (Erik Schlyter). ---------------------------------------- Bug #17058: Array#delete_if doesn't change array instantly https://bugs.ruby-lang.org/issues/17058 * Author: erik_schlyter (Erik Schlyter) * Status: Open * Priority: Normal * ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- According to the documentation: https://ruby-doc.org/core-2.7.1/Array.html#method-i-delete_if "The array is changed instantly every time the block is called, not after the iteration is over." I've tried printing the array while iterating it: ``` a = [1,2,3,4,5,6,7] a.delete_if{|x| puts "During iteration: #{a}" x % 2 == 0 } puts "After iteration: #{a}" ``` The output is as follows: ``` During iteration: [1, 2, 3, 4, 5, 6, 7] During iteration: [1, 2, 3, 4, 5, 6, 7] During iteration: [1, 2, 3, 4, 5, 6, 7] During iteration: [1, 3, 3, 4, 5, 6, 7] During iteration: [1, 3, 3, 4, 5, 6, 7] During iteration: [1, 3, 5, 4, 5, 6, 7] During iteration: [1, 3, 5, 4, 5, 6, 7] After iteration: [1, 3, 5, 7] ``` This functionality has changed somewhere between 2.2.2 and 2.4.0. When I use "ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]", I get the following (correct) output: ``` During iteration: [1, 2, 3, 4, 5, 6, 7] During iteration: [1, 2, 3, 4, 5, 6, 7] During iteration: [1, 3, 4, 5, 6, 7] During iteration: [1, 3, 4, 5, 6, 7] During iteration: [1, 3, 5, 6, 7] During iteration: [1, 3, 5, 6, 7] During iteration: [1, 3, 5, 7] After iteration: [1, 3, 5, 7] ``` When I use "ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux]" or the latest (2.7.1), I get the wrong output. The functionality doesn't seem crucial, but the documentation should be correct. -- https://bugs.ruby-lang.org/