Project

General

Profile

Feature #14606

Change begin-else-end without rescue from warning to syntax error

Added by joker1007 (Tomohiro Hashidate) 11 months ago. Updated 11 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:86134]

Description

begin
  p :foo
else
  p :bar
end

# => :foo
# => :bar
[1,2,3].each do
  p :foo
else
  p :bar
end

# => :foo
# => :bar

begin-else-end without rescue is useless and dangerous. (especially, do-else-end is easy to mistake)
In actually, programmer never intend to write like these.
Ruby interpreter can guard this case by syntax error.

History

Updated by matz (Yukihiro Matsumoto) 11 months ago

Accepted.

Matz.

Updated by mame (Yusuke Endoh) 11 months ago

I'm not against the removeal.

BTW, surprisingly, the following code works "as intended."

def fib(x)
  if x >= 2
    a = fib(x - 1)
    b = fib(x - 2)
    return a + b
  end else x
end

p fib(10) #=> 55

Also available in: Atom PDF