From: shyouhei@... Date: 2018-07-06T04:03:23+00:00 Subject: [ruby-core:87831] [Ruby trunk Bug#14897] Unexpected behavior of `if` in specific code Issue #14897 has been updated by shyouhei (Shyouhei Urabe). Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN to 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED Seems `obj = obj` is (mistakenly) optimized out. ``` % ./miniruby --dump=i -v tmp.rb ruby 2.6.0dev (2018-07-06 trunk 63854) [x86_64-darwin15] == disasm: #@tmp.rb:1 (1,0)-(10,16)> (catch: FALSE) 0000 putspecialobject 1 ( 1)[Li] 0002 putobject :seems_bug 0004 putiseq seems_bug 0006 opt_send_without_block , 0009 pop 0010 putself ( 10)[Li] 0011 putstring "foo" 0013 opt_send_without_block , 0016 leave == disasm: # (catch: FALSE) local table (size: 1, argc: 1 [opts: 0, rest: -1, post: 0, block: -1, kw: -1@-1, kwrest: -1]) [ 1] obj@0 0000 getlocal_WC_0 obj@0 ( 2)[LiCa] 0002 branchif 8 0004 getlocal_WC_0 obj@0 0006 branchif 18 0008 putself ( 5)[Li] 0009 getlocal_WC_0 obj@0 0011 opt_send_without_block , 0014 opt_send_without_block , 0017 pop 0018 getlocal_WC_0 obj@0 ( 7)[Li] 0020 leave ( 8)[Re] ``` ---------------------------------------- Bug #14897: Unexpected behavior of `if` in specific code https://bugs.ruby-lang.org/issues/14897#change-72848 * 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: 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: