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=-3.1 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FORGED_GMAIL_RCVD,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, 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 00E4D1F461 for ; Tue, 14 May 2019 08:14:07 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 5AEFC1209D6; Tue, 14 May 2019 17:14:01 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 08C771208CD for ; Tue, 14 May 2019 17:13:58 +0900 (JST) Received: by filter0067p3las1.sendgrid.net with SMTP id filter0067p3las1-2986-5CDA78C7-15 2019-05-14 08:13:59.545517282 +0000 UTC m=+51140.068578289 Received: from herokuapp.com (unknown [52.72.240.185]) by ismtpd0021p1iad2.sendgrid.net (SG) with ESMTP id 610jXbOcSSqrDwUc4JzWug for ; Tue, 14 May 2019 08:13:59.329 +0000 (UTC) Date: Tue, 14 May 2019 08:13:59 +0000 (UTC) From: sawadatsuyoshi@gmail.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 68126 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 15848 X-Redmine-Issue-Author: sos4nt X-Redmine-Sender: sawa 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?jFXA8Rt481sXUUIO9tYW1AJlMOZdNdlSw=2F5TfLCefGtyZWm5cTGZ7IKUegJBQp?= =?us-ascii?Q?57MBSfHaDaDKGXWO4KnEhxzX4aSYd+x=2FIxmqiRF?= =?us-ascii?Q?Y5REh1sNHoL4p70neuURjS8LkbedznumUq3uJQB?= =?us-ascii?Q?tPRk9eNnQs0=2FhEaxubkH8tpRVNxAX1SajIcLnxn?= =?us-ascii?Q?pk9erGUocL5bKr3dGzKGN6U7n=2FEBrNgAPHg=3D=3D?= To: ruby-core@ruby-lang.org X-ML-Name: ruby-core X-Mail-Count: 92643 Subject: [ruby-core:92643] [Ruby trunk Feature#15848] Silence warning when conditional assignments are wrapped in parentheses 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="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #15848 has been updated by sawa (Tsuyoshi Sawada). Why does the parentheses indicate that assignment is intended, and not comp= arison? ---------------------------------------- Feature #15848: Silence warning when conditional assignments are wrapped in= parentheses https://bugs.ruby-lang.org/issues/15848#change-78006 * Author: sos4nt (Stefan Sch=FC=DFler) * Status: Open * Priority: Normal * Assignee: = * Target version: = ---------------------------------------- Sometime it's convenient to have an assignment in an `if`-condition. The Ru= by documentation even contains an example showing this *"most common use of= side-effect"* practice: http://ruby-doc.org/core-2.6.3/doc/syntax/control_expressions_rdoc.html#lab= el-if+Expression ```ruby if a =3D object.some_value # do something to a end ``` Running that code however results in a warning: > warning: found =3D in conditional, should be =3D=3D It's very unfortunate that the Ruby docs contain example code that the pars= er complains about. And it's unfortunate that we can't make use of conditio= nal assignments without getting warnings or turning off warnings. I propose an obvious change to the current warning mechanism: **Don't show the warning when the assignment is wrapped in parentheses.** ```ruby if a =3D object.some_value # warning end if (a =3D object.some_value) # no warning end ``` This is the way RoboCop already works and it's also a known workaround from= other languages. It would also allow the documentation to contain a warning-free example. -- = https://bugs.ruby-lang.org/ Unsubscribe: