Project

General

Profile

Bug #10947

Multiline if statement returns unexpected value instead of raising a syntax error

Added by sampd (Sam Davies) over 5 years ago. Updated over 5 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:68448]

Description

Here is an invalid multiline if statement

if (false &&
    false &&
    false
    true)
    puts "I was expecting an exception but saw this message instead"
end

As far as I can tell this is and should never be interpreted as valid syntax.

What actually happens is instead of raising an exception, ruby ignores all values except the last and only evaluates that. If you forget a && at the end of a line this can result in very unexpected behavior.

Updated by jeremyevans0 (Jeremy Evans) over 5 years ago

Sam Davies wrote:

Here is an invalid multiline if statement

if (false &&
false &&
false
true)

This is valid syntax. ruby parses this as:

if (false && false && false; true)

This is expected behavior, and changing how ruby handles this would break working code.

Updated by sampd (Sam Davies) over 5 years ago

Jeremy Evans wrote:

This is valid syntax. ruby parses this as:

if (false && false && false; true)

This is expected behavior, and changing how ruby handles this would break working code.

Ah I see, so Ruby interprets the newline as ;. Thanks, I'll watch out for this more carefully in future.

I guess this issue can be closed.

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

  • Description updated (diff)
  • Status changed from Open to Rejected

Also available in: Atom PDF