Project

General

Profile

Actions

Bug #14897

closed

Unexpected behavior of `if` in specific code

Added by peitetsu (teppei takeo) about 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]
[ruby-core:87830]

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"

Related issues

Related to Ruby master - Bug #14974: "if" statement executes wrong branchClosedActions
Related to Ruby master - Bug #14959: Writing a "link_to" method and a "url_helper" with a request parameter under certain "if else" statement in Rails helper crashes with KERN_INVALID_ADDRESS at 0x0000000000000000ClosedActions
Related to Ruby master - Bug #15385: Ruby process hang in ensureClosedActions
Has duplicate Ruby master - Bug #15021: Segfault when compiling certain code on Ruby 2.5.1ClosedActions
Actions

Also available in: Atom PDF