Issue #14897 has been reported by peitetsu (teppei takeo).

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

* Author: peitetsu (teppei takeo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
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>