Project

General

Profile

Bug #14562

Do not warn for assignment in conditionals inside ()

Added by matsuda (Akira Matsuda) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.0dev (2018-03-01 trunk 62617) [x86_64-darwin16]
[ruby-core:85872]

Description

Ruby warns against this code, which is very helpful.

% ruby -we 'if a=1; p a; end'
-e:1: warning: found = in conditional, should be ==
1

So there's a commonly known practice. In order to express that we're intentionally assigning (not missing one more = sign), we usually add parens around the assignment.

But in fact, Ruby still warns...

% ruby -we 'if (a=1); p a; end'
-e:1: warning: found = in conditional, should be ==
1

Can this behavior changed not to warn when parenthesized?


Related issues

Has duplicate Ruby master - Feature #15848: Silence warning when conditional assignments are wrapped in parenthesesRejectedActions

Associated revisions

Revision c9ecea33
Added by nobu (Nobuyoshi Nakada) over 1 year ago

parse.y: refine assign_in_cond warning

  • parse.y (assign_in_cond): refine a warning message for assignment of a literal in conditinal expression. [ruby-core:85872] [Bug #14562]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 62620
Added by nobu (Nobuyoshi Nakada) over 1 year ago

parse.y: refine assign_in_cond warning

  • parse.y (assign_in_cond): refine a warning message for assignment of a literal in conditinal expression. [ruby-core:85872] [Bug #14562]

Revision 62620
Added by nobu (Nobuyoshi Nakada) over 1 year ago

parse.y: refine assign_in_cond warning

  • parse.y (assign_in_cond): refine a warning message for assignment of a literal in conditinal expression. [ruby-core:85872] [Bug #14562]

History

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

Just remove if.
It is the warning for assignment of a literal, which is not "conditional".

#2

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Open to Closed

Applied in changeset trunk|r62620.


parse.y: refine assign_in_cond warning

  • parse.y (assign_in_cond): refine a warning message for assignment of a literal in conditinal expression. [ruby-core:85872] [Bug #14562]
#3

Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Has duplicate Feature #15848: Silence warning when conditional assignments are wrapped in parentheses added

Also available in: Atom PDF