Project

General

Profile

Actions

Bug #13005

closed

Inline rescue is inconsistent when rescuing NoMethodError

Added by josh.cheek (Josh Cheek) almost 8 years ago. Updated over 5 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.4.0dev (2016-11-16 trunk 56815) [x86_64-darwin15]
[ruby-core:78486]

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>'

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #12402: Inline rescue behavior inconsistent for method calls with arguments and assignmentClosednobu (Nobuyoshi Nakada)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0