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 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 596401F4CC for ; Thu, 19 Dec 2024 10:58:35 +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=ga3XQX9f; 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=IjZFcqi7; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1734605882; bh=JHx+ASqSeDdnoDwul4o4hIxSOoN5F2Mh8fDBr5zQmOA=; 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=ga3XQX9fD/zZxgivaTb2eRIvUIZVV15+nC2HbwxG0PVND3PUF4aXE8rT8btTmz/jF W/jay168OirjNN4hnOkx9JtdjVR7VjKtPbKGTVUPfTwikxWuaSDtqDP7C0k8TTq+Zm BFKX035aTIqLeyREijsKKObeolwL7mCtNNDFfUBE= Received: from nue.mailmanlists.eu (localhost [IPv6:::1]) by nue.mailmanlists.eu (Postfix) with ESMTP id C3DEF44D1F for ; Thu, 19 Dec 2024 10:58:02 +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=IjZFcqi7; 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 6596944BFD for ; Thu, 19 Dec 2024 10:57:59 +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=rFfaoc1BMHSjhXDfDqMVAwlFMAsP3jAANJCaWDJxysw=; b=IjZFcqi7c0LNt46bpn859EKj+TUjM0B/TxNip6RmUim42djQs5wlGH/lOED6/bTvtQsL rkmnRmRjCe4lSyzxwC7jG166gHOxyHXOxk+XmylOPak34FMjMor59wCx30/airfXyMphWj 14V5LYymkj9sPF/xEgt9YiHEUWYLZfLcxtrQuxsLwoMcpeU5its8Oziz6QSMTo54+AneE0 2sPu0nUhSQGzSnj/C4JN4UQfZGTH+2/5jPKgC3YtNTBJs2z9anTktjEtN2yb+v0tIqScQh ykuXjy1H9LHRHy5+MgfPNnhQVCTAbAIlShxSbaUcuNZFTflN6aL/xIn0lSz1+8fQ== Received: by recvd-786d47b7ff-98fw5 with SMTP id recvd-786d47b7ff-98fw5-1-6763FC36-1C 2024-12-19 10:57:58.514342489 +0000 UTC m=+2986531.315452579 Received: from herokuapp.com (unknown) by geopod-ismtpd-16 (SG) with ESMTP id Ti7siOEQRVmPSEsrAKAVMQ for ; Thu, 19 Dec 2024 10:57:58.498 +0000 (UTC) Date: Thu, 19 Dec 2024 10:57:58 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 20970 X-Redmine-Issue-Author: tompng X-Redmine-Issue-Priority: Normal X-Redmine-Sender: zverok 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: 97004 X-SG-EID: =?us-ascii?Q?u001=2E2c7sy1dFLsL+QDkhemM07gGzYExWvfbkPAV3M4LabdXDM5MZZ7zyIMamL?= =?us-ascii?Q?IaTeAtDk49J53mNB69xWAO7wAv+0Sp9wXz962NB?= =?us-ascii?Q?2S45orBWVRB6=2FqZYXVRw14MlLFMDjgpi2U1V16B?= =?us-ascii?Q?XnUMJCb73vUPE9x+jKs3ms2FJURNcYEyHN31TAs?= =?us-ascii?Q?FpcpfZOi7Lmn7M7icCgOnVhwJDwle7o1pRMKMrO?= =?us-ascii?Q?7hN55TIXFVVlwT=2F23LodV5TbRSVVdeLI+NknRJQ?= =?us-ascii?Q?SMH64ZkA3HRQYMp0vw+KZr5Rxg=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: FVKCBEGSJSE5RD6DSHTE4FAGYKINTLXB X-Message-ID-Hash: FVKCBEGSJSE5RD6DSHTE4FAGYKINTLXB 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:120327] [Ruby master Bug#20970] `it /1/i` raises undefined method 'it' for main (NoMethodError) even if binding.local_variables includes `it` List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "zverok (Victor Shepelev) via ruby-core" Cc: "zverok (Victor Shepelev)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20970 has been updated by zverok (Victor Shepelev). Interesting. Before the change (on `3.4.0dev (2024-12-15T13:36:38Z master 366fd9642f)`) it was an error both with Prism and parse.y: ```bash $ ruby -e "i = 2; [1, 2, 3].each { it /1/i }" -e:1:in 'block in
': undefined method 'it' for main (NoMethodError) $ ruby --parser=parse.y -e "i = 2; [1, 2, 3].each { it /1/i }" -e:1:in 'block in
': undefined method 'it' for main (NoMethodError) ``` As far as I can guess (by IRB syntax highlighting), `it /1/i` parses at once as `it(/1/i)` (with `/1/i` treated as a regexp literal). Reproduced in other ambiguous cases (that are resolved by local name presence, for all I can understand), say: ```bash ruby -e "[1, 2, 3].each { it + 1 }" #=> OK $ ruby -e "[1, 2, 3].each { it +1 }" -e:1:in 'block in
': undefined method 'it' for main (NoMethodError) $ ruby -e "[1, 2, 3].each { |it| it +1 }" #=> OK ``` I.e., ambiguous operators parsing decisions are made based on whether `it` is known to be a local var (then it is `it.+(1)`), or not known (then it is tentatively considered `it(+1)`). ---------------------------------------- Bug #20970: `it /1/i` raises undefined method 'it' for main (NoMethodError) even if binding.local_variables includes `it` https://bugs.ruby-lang.org/issues/20970#change-111099 * Author: tompng (tomoya ishida) * Status: Open * ruby -v: ruby 3.4.0dev (2024-12-19T07:16:12Z master 335bba0fde) +PRISM [x86_64-linux] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- `it` parameter became a local variable with #20965, but it does not behave like local variable with `--parser=prism` ~~~ruby i=2 42.tap do p it # 42 p local_variables # [:it, :i] p it /1/i # should be 21, got NoMethodError end ~~~ It prints `42`, `[:it, :i], `21` with `--parser=parse.y` -- 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/