From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=-1.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Received: from nue.mailmanlists.eu (nue.mailmanlists.eu [94.130.110.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id D4C301F548 for ; Mon, 2 Sep 2024 10:19:58 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; unprotected) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=xJLq9gE5; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=l4akrnA4; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1725272396; bh=5CYIzriaZFQprSsBIfgB5qD2Dm91W5LG2QP55uhIR0M=; h=Date:References:To:Reply-To:Subject:List-Id:List-Archive: List-Help:List-Owner:List-Post:List-Subscribe:List-Unsubscribe: From:Cc:From; b=xJLq9gE5eZHVhC5vblYfqpRD85CbYIzerVzkoNjtyK41xqAzxPCjhGRByi8pKcmIS w7JWsTLMNHvOXCgYE/PyOMIe67SGERastJA/nZKLnGNpqtKC03dPfi+SAJ1nqM6u32 svDxiXwK9n1Jf3tpapqxZneglEL6cSokPinV6dYA= Received: from nue.mailmanlists.eu (localhost [IPv6:::1]) by nue.mailmanlists.eu (Postfix) with ESMTP id 5A24643F7B for ; Mon, 2 Sep 2024 10:19:56 +0000 (UTC) Authentication-Results: nue.mailmanlists.eu; dkim=pass (2048-bit key; unprotected) header.d=ruby-lang.org header.i=@ruby-lang.org header.a=rsa-sha256 header.s=s1 header.b=l4akrnA4; dkim-atps=neutral Received: from s.wfbtzhsw.outbound-mail.sendgrid.net (s.wfbtzhsw.outbound-mail.sendgrid.net [159.183.224.105]) by nue.mailmanlists.eu (Postfix) with ESMTPS id 22C6B43D8B for ; Mon, 2 Sep 2024 10:19:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ruby-lang.org; h=from:references:subject:mime-version:content-type: content-transfer-encoding:list-id:to:cc:content-type:from:subject:to; s=s1; bh=SwRZWl/k7SipTqyQ06u3iqFS884aN6pMWIkKW3kb5Nk=; b=l4akrnA4qf36kQii0FKDsNqrY0VmOI50BcNwJsec6+x/woE4Ddcs89ZKdn0ZPemMCccR GmKTm0TtlYIU4US6mFQH8+4ZNwc6xYeun+w2R0MS/iW1nkT2bw16xkTSJlWwYJamZdq+kv YlIotYQ7FpSdxyqm15V20FoxpEu6mX4soW7GkkuE+fpeJjhQaIyyhaRsdQeTNYOZIdoPLO 5Dfgm47aAE/xGtxH6NK4FQhVeSSjCt1CKHWbXJYI9SrORKqnnFZsK+i82ls9zAIVfYWFHi RPpLFULMYaoXIk+yMLJho1MupWfEA0KalLpCiyd5Fp34G1RB/1K8BzWgnNcXw5yA== Received: by recvd-6b556c7f5c-7f4pq with SMTP id recvd-6b556c7f5c-7f4pq-1-66D5913E-9 2024-09-02 10:19:42.492732319 +0000 UTC m=+993843.480382592 Received: from herokuapp.com (unknown) by geopod-ismtpd-22 (SG) with ESMTP id V2AmLRLATIG9DvY3dl605Q for ; Mon, 02 Sep 2024 10:19:42.418 +0000 (UTC) Date: Mon, 02 Sep 2024 10:19:42 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 20701 X-Redmine-Issue-Author: pabloh X-Redmine-Issue-Priority: Normal X-Redmine-Sender: k0kubun 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-Redmine-MailingListIntegration-Message-Ids: 95653 X-SG-EID: =?us-ascii?Q?u001=2EsWSpkbcla4bB6tSlkOwdN01=2FLLwMflJlYDs0Ak3Gg6dwg4YUERnU2ZQsI?= =?us-ascii?Q?KPesnHmuO3R4nEnLV41FQje7rMJs=2FlByQKQxPtJ?= =?us-ascii?Q?4AIt7Pq58gChghtCxd5DmSE34gY1P7LuBy1Mh+L?= =?us-ascii?Q?6aj7gPuLGLnq01R7Eey1BKGrsr8FqNYKlgf3UaB?= =?us-ascii?Q?Ffm4X33kzjYajnjECmuow+6eCXrWRwEwHv7cfoq?= =?us-ascii?Q?Cj4Q9FH1SerwE40sB7ADmi+hZzFTy=2FqIDLR4Dat?= =?us-ascii?Q?hc=2F5GnRDEW6PzZ1jsRYclyVU5Q=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: FPBVXZLSA2Z5QVOTEFDXXFG3MEIWV3XB X-Message-ID-Hash: FPBVXZLSA2Z5QVOTEFDXXFG3MEIWV3XB X-MailFrom: bounces+313651-b711-ruby-core=ml.ruby-lang.org@em5188.ruby-lang.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:119014] [Ruby master Bug#20701] Hash argument passed as keyword splat can be mutated inside method List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "k0kubun (Takashi Kokubun) via ruby-core" Cc: "k0kubun (Takashi Kokubun)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20701 has been updated by k0kubun (Takashi Kokubun). Backport changed from 3.1: DONTNEED, 3.2: DONTNEED, 3.3: REQUIRED to 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONE ruby_3_3 commit:cf9a6c2b63e6337a3f6ce76527446739e5aceb67 merged revision(s) commit:a3562c2a0abf1c2bdd1d50377b4f929580782594. ---------------------------------------- Bug #20701: Hash argument passed as keyword splat can be mutated inside method https://bugs.ruby-lang.org/issues/20701#change-109589 * Author: pabloh (Pablo Herrero) * Status: Closed * ruby -v: ruby 3.4.0dev (2024-08-27T00:39:24Z master e5295644c9) [x86_64-linux] * Backport: 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONE ---------------------------------------- If you call a method with a splatted kwargs that also uses a splatted array followed by at least one positional argument, the called method can mutate the splatted kwargs. ``` ruby def foo(a, h) h[:splat_modified] = true end a = [] b = {splat_modified: false} foo(*a, :x, **b) b[:splat_modified] # Should be 'false' but is 'true' # It makes no difference if the called method expects a kwargs def foo2(a, **h) h[:splat_modified] = true end b[:splat_modified] = false foo2(*a, :x, **b) b[:splat_modified] # Should be 'false' but is 'true' # The case when a block is also pass is broken too c = proc { } b[:splat_modified] = false foo(*a, :x, **b, &c) b[:splat_modified] # Should be 'false' but is 'true' # When the extra positional argument after the array splat is removed the correct behavior is restored b[:splat_modified] = false foo(*a, **b) foo(*a, :x, **b, &c) b[:splat_modified] # Is 'false' ``` Apparently, this problem is due to the `KW_SPLAT_MUT` flag being set at the method's call site: `ruby --dump=insns,-optimize -e 'a, b, c = [4,6,4],{a: 3},:ds; foo(*a,9,**c)` outputs ``` 0000 duparray [4, 6, 4] ( 1)[Li] 0002 duphash {:a=>3} 0004 putobject :ds 0006 setlocal c@2, 0 0009 setlocal b@1, 0 0012 setlocal a@0, 0 0015 putself 0016 getlocal a@0, 0 0019 splatarray true 0021 putobject 9 0023 pushtoarray 1 0025 getlocal c@2, 0 0028 send , nil 0031 leave ``` The error is present in both 3.3 and 3.4: - ruby 3.4.0dev (2024-08-27T00:39:24Z master e5295644c9) [x86_64-linux] - ruby 3.3.4 (2024-07-09 revision be1089c8ec) [x86_64-linux] PR for test: https://github.com/ruby/ruby/pull/11467 -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/