Project

General

Profile

Bug #15932

wrong "void value expression" error for 'next' or 'break' statements inside an 'if' assignment

Added by cvss (Kirill Vechera) 10 months ago. Updated 10 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
1.8.7, 2.7.0preview1
[ruby-core:93199]

Description

When a 'next' or 'break' statement for block/loop control is placed inside an 'if' assignment, the parser outputs an error "void value expression". The same parsing error raises for the ternary operator in the same conditions.

I think, the the correct behavior should be consistent with the behavior of the 'case' statement, that is parsing such a code without errors and leaving the right-side variable with 'nil' value.

Examples of code giving a "void value expression" error:

1.

begin
    a = if false
        'A'
    else
        next
    end
end while false

2.

begin
    a = false ? 'A' : next
end while false

Example of code running without errors:

3.

begin
    a = case false
        when true
            'A'
        else
            next
        end
end while false

4.

begin
    a = (false or next)
end while false

Related issues

Related to Ruby master - Bug #11143: it should always be possible to return from an ifClosedActions
#1

Updated by cvss (Kirill Vechera) 10 months ago

  • ruby -v changed from 1.8.7 .. 2.7.0preview1 to 1.8.7, 2.7.0preview1
#2

Updated by nobu (Nobuyoshi Nakada) 10 months ago

  • Backport changed from 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN to 2.4: REQUIRED, 2.5: REQUIRED, 2.6: REQUIRED
#3

Updated by nobu (Nobuyoshi Nakada) 10 months ago

  • Status changed from Open to Closed

Applied in changeset git|01b3a3804334be19d013526d3edde2b84399ae43.


Fix wrong "void value expression" error

  • parse.y (value_expr_check): if either of then or else statements is not a void value expression, the whole if is not also a void value expression. [Bug #15932]
#4

Updated by jeremyevans0 (Jeremy Evans) 9 months ago

  • Related to Bug #11143: it should always be possible to return from an if added

Also available in: Atom PDF