Actions
Bug #14459
closedUnexpected compile error in 2.5.0
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]
Description
I created this script as test.rb.
h = { us: 'dollar', india: 'rupee' }
# 変数hのキーと値を**で展開させる
{ japan: 'yen', **h } #=> {:japan=>"yen", :us=>"dollar", :india=>"rupee"}
# **を付けない場合は構文エラーになる
# { japan: 'yen', h }
#=> SyntaxError: syntax error, unexpected '}', expecting =>
# { japan: 'yen', h }
# ^
# ----------------------------------------
h = { us: 'dollar', india: 'rupee' }
{ japan: 'yen' }.merge(h) #=> {:japan=>"yen", :us=>"dollar", :india=>"rupee"}
In Ruby 2.4.3 it runs without errors, but in Ruby 2.5.0 it fails with compile error (SyntaxError).
➜ Desktop rbenv shell 2.4.3
➜ Desktop ruby -v
ruby 2.4.3p205 (2017-12-14 revision 61247) [x86_64-darwin17]
➜ Desktop ruby test.rb
➜ Desktop rbenv shell 2.5.0
➜ Desktop ruby -v
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17]
➜ Desktop ruby test.rb
-- raw disasm--------
<L508596008>
trace: 1
0000 putobject :us ( 1)
0002 putstring "dollar" ( 1)
0004 putobject :india ( 1)
0006 putstring "rupee" ( 1)
0008 newhash 4 ( 1)
0010 setlocal_OP__WC__0 3 ( 1)
trace: 1
*0012 newhash 2 ( 3)
0014 getlocal_OP__WC__0 3 ( 3)
0016 pop ( 3)
trace: 1
0017 putobject :us ( 13)
0019 putstring "dollar" ( 13)
0021 putobject :india ( 13)
0023 putstring "rupee" ( 13)
0025 newhash 4 ( 13)
0027 setlocal_OP__WC__0 3 ( 13)
trace: 1
0029 putobject :japan ( 14)
0031 putstring "yen" ( 14)
0033 newhash 2 ( 14)
0035 getlocal_OP__WC__0 3 ( 14)
0037 opt_send_without_block <callinfo:merge, 1>, <call cache> ( 14)
0040 leave ( 14)
---------------------
test.rb:3: argument stack underflow (-1)
Traceback (most recent call last):
test.rb: compile error (SyntaxError)
I attached actual test.rb. I think it should run without errors in Ruby 2.5.0 too.
Files
Updated by wanabe (_ wanabe) almost 7 years ago
git bisect
tells that this is since r61329 [Bug #14201].
$ git checkout 5c3f9641c0475b6ec2e26c8e6df921abf47856ca~
Previous HEAD position was 5c3f9641c0... compile.c: side effect in splat
HEAD is now at 494b3aeaea... Use syswrite to avoid potential buffering in IO#select spec
$ make REVISION_FORCE=PHONY .revision.time miniruby >/dev/null 2>&1 && ./miniruby -ve 'h = { us: "dollar", india: "rupee" }; { japan: "yen", **h }; true'
ruby 2.5.0dev (2017-12-19 trunk 61327) [x86_64-linux]
-e:1: warning: possibly useless use of true in void context
$ git checkout 5c3f9641c0475b6ec2e26c8e6df921abf47856ca
Previous HEAD position was 494b3aeaea... Use syswrite to avoid potential buffering in IO#select spec
HEAD is now at 5c3f9641c0... compile.c: side effect in splat
$ make REVISION_FORCE=PHONY .revision.time miniruby >/dev/null 2>&1 && ./miniruby -ve 'h = { us: "dollar", india: "rupee" }; { japan: "yen", **h }; true'
ruby 2.5.0dev (2017-12-19 trunk 61329) [x86_64-linux]
-e:1: warning: possibly useless use of true in void context
-- raw disasm--------
<L-35872528>
trace: 1
0000 putobject :us ( 1)
0002 putstring "dollar" ( 1)
0004 putobject :india ( 1)
0006 putstring "rupee" ( 1)
0008 newhash 4 ( 1)
0010 setlocal_OP__WC__0 3 ( 1)
*0012 newhash 2 ( 1)
0014 putspecialobject 1 ( 1)
0016 swap ( 1)
0017 getlocal_OP__WC__0 3 ( 1)
0019 opt_send_without_block <callinfo:core#hash_merge_kwd, 2>, <call cache>( 1)
0022 pop ( 1)
0023 putobject true ( 1)
0025 leave ( 1)
---------------------
-e:1: argument stack underflow (-1)
Traceback (most recent call last):
-e: compile error (SyntaxError)
Updated by wanabe (_ wanabe) almost 7 years ago
- Related to Bug #14201: Regression due to over optimization of hash splat added
Updated by nobu (Nobuyoshi Nakada) almost 7 years ago
- Status changed from Open to Closed
Applied in changeset trunk|r62333.
compile.c: popped hash
- compile.c (compile_array): skip creating new hash if preceeding
elements are popped all. [ruby-core:85486] [Bug #14459]
Updated by nagachika (Tomoyuki Chikanaga) almost 7 years ago
- Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN to 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED
Updated by naruse (Yui NARUSE) over 6 years ago
- Backport changed from 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED to 2.3: DONTNEED, 2.4: DONTNEED, 2.5: DONE
ruby_2_5 r62527 merged revision(s) 62333.
Actions
Like0
Like0Like0Like0Like0Like0