Project

General

Profile

Actions

Feature #20742

open

Trying to assign to a variable in statement modifier should emit a warning

Added by esad (Esad Hajdarevic) about 1 month ago. Updated about 1 month ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:119199]

Description

There is an example in Control Expressions documentation:

p a if a = 0.zero? # raises NameError “undefined local variable or method ‘a’”.

However, if we had already defined a there would be no exception raised. If one uses something like p for scratch variable, due to Kernel#p, also no exception is raised.

Statement modifier is generally somewhat inverting the code flow (the right part is evaluated first then the left part), so it is not really obvious why binding variables shouldn't follow the same flow. A warning would be very beneficial.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0