Actions
Bug #13005
closedInline rescue is inconsistent when rescuing NoMethodError
Description
o = "some object"
class << o
private
attr_accessor :a
end
# GETTER can be rescued in a begin-block or inline
begin o.a
rescue; $!.class # => NoMethodError
end
o.a rescue $!.class # => NoMethodError
# SETTER can be rescued in a begin-block but NOT inline!
begin o.a = 1
rescue; $!.class # => NoMethodError
end
o.a = 1 rescue $!.class
# ~> NoMethodError
# ~> private method `a=' called for "some object":String
# ~> Did you mean? a
# ~>
# ~> program.rb:18:in `<main>'
Updated by matz (Yukihiro Matsumoto) almost 8 years ago
- Status changed from Open to Closed
o.a = 1 rescue $!.class
is parsed as
o.a = (1 rescue $!.class)
Try
(o.a = 1) rescue $1.class
Matz.
Updated by duerst (Martin Dürst) almost 8 years ago
- Status changed from Closed to Open
- Assignee set to matz (Yukihiro Matsumoto)
@matz (Yukihiro Matsumoto): Is there a good reason that o.a = 1 rescue $!.class
is interpreted as o.a = (1 rescue $1.class)
, while it looks to me as if o.a = 1 if $!.class
is (o.a = 1) if $!.class
?
(Backwards compatibility might be a reasonable good reason, but I can't imagine it being useful.)
Updated by shyouhei (Shyouhei Urabe) almost 8 years ago
Martin Dürst wrote:
@matz (Yukihiro Matsumoto): Is there a good reason that
o.a = 1 rescue $!.class
is interpreted aso.a = (1 rescue $1.class)
, while it looks to me as ifo.a = 1 if $!.class
is(o.a = 1) if $!.class
?(Backwards compatibility might be a reasonable good reason, but I can't imagine it being useful.)
I guess issue #12402 is the reason behind this behaviour.
Updated by shyouhei (Shyouhei Urabe) almost 8 years ago
- Related to Bug #12402: Inline rescue behavior inconsistent for method calls with arguments and assignment added
Updated by jeremyevans0 (Jeremy Evans) over 5 years ago
- Status changed from Open to Closed
Actions
Like0
Like0Like0Like0Like0Like0