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)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 7B1311F55F for ; Sun, 12 May 2024 07:06:04 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (1024-bit key; secure) header.d=ml.ruby-lang.org header.i=@ml.ruby-lang.org header.a=rsa-sha256 header.s=mail header.b=WzgdKacu; 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=lQlVU4Xu; dkim-atps=neutral Received: from nue.mailmanlists.eu (localhost [127.0.0.1]) by nue.mailmanlists.eu (Postfix) with ESMTP id E2B0D8496A; Sun, 12 May 2024 07:05:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ml.ruby-lang.org; s=mail; t=1715497557; bh=WxzjqvLwQIIyYCw670JTdWchynhcuNKU7iSag/BN0Rg=; 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=WzgdKacuU8a1e4+e+G3ZdLSxMF6yKaFbwPB4HSXO58ID81NeiZ3dJqEqZqEfBnTXd +k+neL9oZDjeNzh7PPu8RkIOXZNOqg1jJr0+OAt9r5EQ+pyPPPWbwX1FC45kAuzoQB JMJGz3kJf3Dtd0xB/dYIK3unyISZMDl3rPlN04Yc= Received: from s.wrqvtvvn.outbound-mail.sendgrid.net (s.wrqvtvvn.outbound-mail.sendgrid.net [149.72.120.130]) by nue.mailmanlists.eu (Postfix) with ESMTPS id F36CA848CA for ; Sun, 12 May 2024 07:05:53 +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=lQlVU4Xu; dkim-atps=neutral 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=Hc1iYP7sQC2FliIQbICsq24TE9yBiGM8Ok+PscQQlDk=; b=lQlVU4XuKhUe/6xS2N6+3NuGfWv/oAooFSN+327vg0/m1P9DVUCbN3yYhmDIZu7iBq98 JgYMsr0uTJXG4YTZdhK7h87DGRwIoDbnT0vyiKnLTo2OHVYxkCTWSSYA+AD8EmJouD+IcS z8QKJDH7gJL/OvLDFbwoYgV+lN+5n8CAe55UPCQG2eoFmt/EPOWjH6TzboEgmZLy4SKNYt TxK6+3GRJ2MFUVvK44W6ZoDjU4K4SMOurutiaVD0XA4N5qDQMTThoTObP8VyWVIAbHwQyW KVNV9y60BoBU0ytp03wGTMPAiI6y8wD4mpTrqpXzDOMnxipwLAk//yLfMbDjPNUw== Received: by recvd-785ff4475c-rgdxs with SMTP id recvd-785ff4475c-rgdxs-1-66406A50-2D 2024-05-12 07:05:52.919354155 +0000 UTC m=+976460.229552274 Received: from herokuapp.com (unknown) by geopod-ismtpd-8 (SG) with ESMTP id g5ZkCzqqT32hUPP1ONp1tQ for ; Sun, 12 May 2024 07:05:52.889 +0000 (UTC) Date: Sun, 12 May 2024 07:05:52 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Bug X-Redmine-Issue-Id: 20482 X-Redmine-Issue-Author: Soilent X-Redmine-Issue-Priority: Normal 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-Redmine-MailingListIntegration-Message-Ids: 94440 X-SG-EID: =?us-ascii?Q?u001=2E5PtzXJ23KrYzgM1nrOIr+EQ222PyrDaWSg0Er8CZ8tP86xyXmBM81zBKD?= =?us-ascii?Q?HreavdFYMbHjxXOR6UPMkt=2Fu9CyBIp6y52n8D2y?= =?us-ascii?Q?qA9zqurrgUeMpXCzg6HhbkUyQ6WqI6Pp1RkRYLi?= =?us-ascii?Q?CsvK=2FfE8rDaNfM=2Fi3SwEkq3ivVivuPk3J5A98Xi?= =?us-ascii?Q?Svc+xp=2F21nYAQsBoMDk9410pa3+RvLywzT=2F4FrL?= =?us-ascii?Q?0a2twHgPpo7uvxATB22EDcLH2IxScCt9p6gtGmf?= =?us-ascii?Q?UQmXfrF1OHCVV2EfrmlUkjNCFQ=3D=3D?= To: ruby-core@ml.ruby-lang.org X-Entity-ID: u001.I8uzylDtAfgbeCOeLBYDww== Message-ID-Hash: UPBK5LUHTXPCPER6CPIDQF6HKFFDODL5 X-Message-ID-Hash: UPBK5LUHTXPCPER6CPIDQF6HKFFDODL5 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.3 Precedence: list Reply-To: Ruby developers Subject: [ruby-core:117844] [Ruby master Bug#20482] nil variables in a guard clause of a standalone => or in expression List-Id: Ruby developers Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: "nobu (Nobuyoshi Nakada) via ruby-core" Cc: "nobu (Nobuyoshi Nakada)" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Issue #20482 has been updated by nobu (Nobuyoshi Nakada). Soilent (Konstantin x) wrote in #note-2: > Thank you, nobu! That explains it. > > Just to clarify, is this how the expression is parsed? > > ```ruby > ( [1, 2] in a, b ) if b == 2*a > ``` Yes, you can confirm the AST by `ruby --dump=parsetree -e '1 in a if a'` (the code is simplified). > And since this is a modifier `if`, the parser creates variables a and b first, which is why they are defined in the test expression? Yes, `a` and `b` are created by `[1, 2] in a, b` and available in the `if` condition. ---------------------------------------- Bug #20482: nil variables in a guard clause of a standalone => or in expression https://bugs.ruby-lang.org/issues/20482#change-108249 * Author: Soilent (Konstantin x) * Status: Open * ruby -v: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23] * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- The following expression produces a TypeError, which is quite unexpected: ```ruby [1, 2] in a, b if b == 2*a ``` ``` x.rb:1:in `*': nil can't be coerced into Integer (TypeError) [1, 2] in a, b if b == 2*a ^ from x.rb:1:in `
' ``` The expression above should be equivalent to the following one, which works as expected: ```ruby case [1, 2] in a, b if b == 2*a true else false end # => true ``` Apologies in advance if this is intentional or has been reported before. -- 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/postorius/lists/ruby-core.ml.ruby-lang.org/