Project

General

Profile

Actions

Bug #12402

closed

Inline rescue behavior inconsistent for method calls with arguments and assignment

Added by bklang (Ben Klang) almost 8 years ago. Updated over 7 years ago.

Status:
Closed
Target version:
-
[ruby-core:75621]

Description

In this example l'm intentionally passing bad data to Date.parse to trigger an exception. Depending on whether I use parenthesis in the method call, and whether I assign the result, I get different behavior for the inline rescue.

Code:

var1 = "apple"
var1 = Date.parse var1 rescue nil

var2 = "apple"
var2 = Date.parse(var2) rescue nil

def example1(bar)
  Date.parse bar rescue nil
end

def example2(bar)
  bar = Date.parse bar rescue nil
  bar
end

def example3(bar)
  bar = Date.parse(bar) rescue nil
  bar
end

puts "Variable 1: #{var1.nil?}"
puts "Variable 2: #{var2.nil?}"
puts "Example method 1: #{example1("apple").nil?}"
puts "Example method 2: #{example2("apple").nil?}"
puts "Example method 3: #{example3("apple").nil?}"

I would expect all 5 outputs from the above script to return true.

Example:

Variable 1: false
Variable 2: true
Example method 1: true
Example method 2: false
Example method 3: true

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #13005: Inline rescue is inconsistent when rescuing NoMethodErrorClosedmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0