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=AWL,BAYES_00, 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 821CD1F463 for ; Sat, 21 Sep 2019 07:09:38 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id C0341120A95; Sat, 21 Sep 2019 16:09:28 +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 24A77120A8E for ; Sat, 21 Sep 2019 16:09:26 +0900 (JST) Received: by filter0096p3iad2.sendgrid.net with SMTP id filter0096p3iad2-26369-5D85CCA9-B 2019-09-21 07:09:29.201412663 +0000 UTC m=+135913.922235905 Received: from herokuapp.com (unknown [3.85.105.179]) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id MvroMnI5TuCIepAnqJuP4g for ; Sat, 21 Sep 2019 07:09:29.119 +0000 (UTC) Date: Sat, 21 Sep 2019 07:09:29 +0000 (UTC) From: nobu@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 70567 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 16173 X-Redmine-Issue-Author: burdettelamar@yahoo.com X-Redmine-Sender: nobu 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?q8Dly+pU2+3ektTtZVXgZtbJPXwqo7p86jCsvYTW4By3nDYwTO4k4DsPGTvxTn?= =?us-ascii?Q?=2Ft8jyGeAM3ipK0k8Y7kfYViQwVWh+Y3VeVVMy4H?= =?us-ascii?Q?tIjgD8ip2k43H7LM2iUciGLgYDFMnbi5Agy0eMM?= =?us-ascii?Q?UYQ0rDfA9+cSQlXlv0ZsQZ+k5aH7ki70ALd5nxM?= =?us-ascii?Q?S+a2D8niAVhdX4b6uX+43HsXjKYlPcUNWLg=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 95012 Subject: [ruby-core:95012] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given 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 #16173 has been updated by nobu (Nobuyoshi Nakada). Comparing with `Hash#delete`, it looks that the document is correct and the code is wrong. ```diff diff --git i/hash.c w/hash.c index 8b84a14484..7880178dc8 100644 --- i/hash.c +++ w/hash.c @@ -4779,7 +4779,7 @@ env_delete_m(VALUE obj, VALUE name) VALUE val; val = env_delete(name); - if (NIL_P(val) && rb_block_given_p()) rb_yield(name); + if (NIL_P(val) && rb_block_given_p()) val = rb_yield(name); return val; } diff --git i/test/ruby/test_env.rb w/test/ruby/test_env.rb index b01c3b12ee..1a7656ea7d 100644 --- i/test/ruby/test_env.rb +++ w/test/ruby/test_env.rb @@ -107,6 +107,7 @@ assert_invalid_env {|v| ENV.delete(v)} assert_nil(ENV.delete("TEST")) assert_nothing_raised { ENV.delete(PATH_ENV) } + assert_equal("NO TEST", ENV.delete("TEST") {|name| "NO "+name}) end def test_getenv ``` ---------------------------------------- Bug #16173: ENV.delete returns nil when name does not exist and block given https://bugs.ruby-lang.org/issues/16173#change-81639 * Author: burdettelamar@yahoo.com (Burdette Lamar) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.6.4p104 (2019-08-28 revision 67798) [x64-mingw32] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- Attached diff.txt: * ENV.delete for nonexistent name and block given: * Test enhanced to verify return value is nil. * Documentation corrected to say that return value is nil, not value. ---Files-------------------------------- diff.txt (961 Bytes) -- https://bugs.ruby-lang.org/