Project

General

Profile

Actions

Bug #21808

open

Inconsistency in support of additional newlines with boolean logical operators on new line

Bug #21808: Inconsistency in support of additional newlines with boolean logical operators on new line

Added by herwin (Herwin W) about 2 months ago. Updated 11 days ago.

Status:
Assigned
Target version:
-
ruby -v:
ruby 4.0.0 (2025-12-25 revision 553f1675f3) +PRISM [x86_64-linux]
[ruby-core:124367]

Description

With this I mean the new Ruby 4 feature.

With the old style, one could add additional lines in between:

if true &&

   true
     puts 'match'
end

With the new style, this results in a syntax error

if true

   && true
     puts 'match'
end

If a comment is used instead of a new line, it still works

if true
   # blah
   && true
     puts 'match'
end

This happens with both prism and parse.y

I doubt anyone would want to write code like this (I don't think it improves the layout), but it's still a weird inconsistency that doesn't get mentioned.

Updated by mame (Yusuke Endoh) about 2 months ago Actions #1 [ruby-core:124368]

  • Status changed from Open to Assigned
  • Assignee set to matz (Yukihiro Matsumoto)

If I recall, this is intentional. A blank line before a period for a method call also causes a parsing error.

$ ruby -e '"foo"
>
> .upcase'
-e: -e:3: syntax error found (SyntaxError)
  1 | "foo"
  2 |
> 3 | .upcase
    | ^ unexpected '.', ignoring it

That said, I personally agree that it looks inconsistent. I'd like to confirm this with Matz.

Updated by nobu (Nobuyoshi Nakada) about 2 months ago Actions #2 [ruby-core:124371]

  • Backport changed from 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.2: DONTNEED, 3.3: DONTNEED, 3.4: DONTNEED, 4.0: UNKNOWN

That blank line separates code visually, so continuing beyond it doesn't look nice to me.

Updated by matz (Yukihiro Matsumoto) 11 days ago Actions #3 [ruby-core:124780]

I agreed with @nobu (Nobuyoshi Nakada) here. Fluent method calls (.) behave same.

Matz.

Actions

Also available in: PDF Atom