Actions
Bug #14897
closedUnexpected behavior of `if` in specific code
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]
Description
I found a strange behavior of if
in the following code.
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.
def seems_bug(obj)
if obj || any1
any2 = any2
else
raise obj.inspect
end
obj
end
seems_bug('foo')
#=> RuntimeError: "foo"
Actions
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0