Project

General

Profile

Actions

Bug #14824

closed

Endless Range Support in irb

Added by jeremyevans0 (Jeremy Evans) over 6 years ago. Updated almost 4 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.6.0preview2 (2018-05-31 trunk 63539) [x86_64-openbsd]
[ruby-core:87394]
Tags:

Description

irb currently doesn't have great support for endless ranges, forcing you to use explicit parentheses around the endless range. Without explicit parentheses, it treats the endless range as a line continuation.

irb(main):001:0> 1..
irb(main):002:0* ;
=> 1..
irb(main):003:0> (1..)
=> 1..
irb(main):004:0>

Ranges with ends do not require parentheses in irb, and endless ranges should have the same behavior.


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #14808: Last token of endless range should have EXPR_ENDRejectedActions
Actions #2

Updated by aycabta (aycabta .) over 6 years ago

  • Related to Feature #14808: Last token of endless range should have EXPR_END added

Updated by aycabta (aycabta .) over 6 years ago

  • Status changed from Open to Rejected

It's a correct behavior. This ticket is the same arguments for #14808.

Updated by mame (Yusuke Endoh) over 6 years ago

First of all, I have no strong opinion about this issue. The current behavior of irb looks weird to me, but it may be okay because irb users can work around the issue easily.

In principle, I expect irb to cut the shortest lines that parses. For example, consider the following input:

foo
.bar

Irb first evaluates only the first line foo, and the second line .bar causes SyntaxError. This is the behavior that I expect. In the same logic, I expect 1.. to be cut because it parses.

irb(main):001:0> 1..

BTW, a line obj.+ causes line continuation. This is a behavior that I don't expect:

irb(main):001:0> obj = Object.new
=> #<Object:0x0000560275fa4b00>
irb(main):002:0> def obj.+(); 42; end
=> :+
irb(main):003:0> obj.+
irb(main):004:0* 
irb(main):005:0* ;
=> 42

If the method name is different than +, say foo, irb does not wait for the next line. Looks very inconsistent.

irb(main):006:0> def obj.foo(); 42;end
=> :foo
irb(main):007:0> obj.foo
=> 42

So, I cannot see any consistent policy about line continuation.

But again, it's okay to me in the case of irb. Few users will encounter such a corner case. Even if someone does, s/he can avoid such a behavior by explicit semicolon or parens or something else.

Updated by aycabta (aycabta .) over 6 years ago

  • Status changed from Rejected to Open

mame (Yusuke Endoh) wrote:

In principle, I expect irb to cut the shortest lines that parses.

Ah, well, you got that right. I understand an importance of this issue. So I re-open this.

BTW, a line obj.+ causes line continuation. This is a behavior that I don't expect:

irb(main):001:0> obj = Object.new
=> #<Object:0x0000560275fa4b00>
irb(main):002:0> def obj.+(); 42; end
=> :+
irb(main):003:0> obj.+
irb(main):004:0* 
irb(main):005:0* ;
=> 42

It will be fixed by https://bugs.ruby-lang.org/issues/14683, but this issue will not. Therefore, I guess that https://bugs.ruby-lang.org/issues/14808 is needed for this issue too.

Updated by jeremyevans0 (Jeremy Evans) almost 4 years ago

  • Status changed from Open to Assigned
  • Assignee set to aycabta (aycabta .)

I've submitted a pull request to fix this issue: https://github.com/ruby/irb/pull/195

Actions #7

Updated by jeremyevans (Jeremy Evans) almost 4 years ago

  • Status changed from Assigned to Closed

Applied in changeset git|2cc5827fdca97dbd1225a49a3114d28aa1cb2ef4.


[ruby/irb] Do not continue line if last expression is an endless range

Fixes [Bug #14824]

https://github.com/ruby/irb/commit/63414f8465

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0