Rescue statement modifier behavior change in 1.8.0

So I’m spending my Christmas Eve trying out new versions of Ruby. What a
Christmas present!

The following program works without error in 1.6.8. With the
1.8.0preview1, the rescue statement modifier doesn’t catch the IndexError.
The program terminates with the message:

[tim:~]$ ruby foo.rb
foo.rb:4:in `bar=’: bar too big (IndexError)
from foo.rb:16

Is this a deliberate change in behavior?

Here’s the program:

class Foo
def bar=(b)
if b > 10
raise IndexError, "bar too big"
end
end
end

foo = Foo.new
begin
foo.bar = 11
rescue
foo.bar=10
end

foo.bar = 11 rescue 10
exit

Hi,

So I’m spending my Christmas Eve trying out new versions of Ruby. What a
Christmas present!

The following program works without error in 1.6.8. With the
1.8.0preview1, the rescue statement modifier doesn’t catch the IndexError.
The program terminates with the message:

[tim:~]$ ruby foo.rb
foo.rb:4:in `bar=': bar too big (IndexError)
from foo.rb:16

Is this a deliberate change in behavior?

Yes.

Here’s the program:

class Foo
def bar=(b)
if b > 10
raise IndexError, “bar too big”
end
end
end

foo = Foo.new
begin
foo.bar = 11
rescue
foo.bar=10
end

foo.bar = 11 rescue 10
exit

foo.bar = 11 rescue 10

line was parsed as

(foo.bar = 11) rescue 10

or

begin
foo.bar = 11
rescue
10
end

on 1.6.x. On 1.8.0, it is parsed as

foo.bar = (11 rescue 10)

Put extra parenthesises, if you want the old behavior.

						matz.
···

In message “rescue statement modifier behavior change in 1.8.0” on 02/12/25, “Tim Hunter” cyclists@nc.rr.com writes:

Thanks, Matz! Merry Christmas!

···

On Wed, 25 Dec 2002 08:38:14 +0900, Yukihiro Matsumoto wrote:

Hi,

foo.bar = 11 rescue 10

line was parsed as

(foo.bar = 11) rescue 10

or

begin
foo.bar = 11
rescue
10
end

on 1.6.x. On 1.8.0, it is parsed as

foo.bar = (11 rescue 10)

Put extra parenthesises, if you want the old behavior.

  					matz.