Issue #14897 has been updated by mame (Yusuke Endoh).


Good catch.  It was a bug of peephole optimization.  Fixed.  Thank you.

----------------------------------------
Bug #14897: Unexpected behavior of `if` in specific code
https://bugs.ruby-lang.org/issues/14897#change-72851

* Author: peitetsu (teppei takeo)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]
* Backport: 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED
----------------------------------------
I found a strange behavior of `if` in the following code.

~~~ ruby
def seems_bug(obj)
  if obj || obj
    obj = obj
  else
    raise obj.inspect
  end
  obj
end

seems_bug('foo')
#=> RuntimeError: "foo"
~~~

This code is expected to return "foo", but the error on the else clause occurs. 

The same error occurs in the following code.

~~~ ruby
def seems_bug(obj)
  if obj || any1
    any2 = any2
  else
    raise obj.inspect
  end
  obj
end

seems_bug('foo')
#=> RuntimeError: "foo"
~~~





-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>