diff options
author | yui-knk <spiketeika@gmail.com> | 2023-10-20 21:30:18 +0900 |
---|---|---|
committer | Yuichiro Kaneko <spiketeika@gmail.com> | 2023-10-31 17:49:12 +0900 |
commit | 51149f335e4aea3465bd52a98f85351455bf320e (patch) | |
tree | b3eaf51570be281b7acbf0b2df6a5b058c91dfd1 /test/ruby | |
parent | eff59e93df1102d990a61965d906a28d55abc14a (diff) | |
download | ruby-51149f335e4aea3465bd52a98f85351455bf320e.tar.gz |
Keep unused literal nodes
For static analysis, it’s better to keep unused literal nodes.
If simply change `block_append` to fall through, both "unused literal ignored"
and "possibly useless use of a literal in void context" warnings
are shown for the same line. But it’s verbose then remove
"unused literal ignored" warning.
This kind of optimization is already implemented on compile.c.
`compile_block` calls `iseq_compile_each0` with `popped = 1` when NODE_BLOCK
has next.
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_parse.rb | 9 | ||||
-rw-r--r-- | test/ruby/test_pattern_matching.rb | 2 |
2 files changed, 5 insertions, 6 deletions
diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index cc65f3b849..dcc04a441c 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -876,7 +876,6 @@ x = __ENCODING__ def test_void_expr_stmts_value x = 1 useless_use = /useless use/ - unused = /unused/ assert_nil assert_warning(useless_use) {eval("x; nil")} assert_nil assert_warning(useless_use) {eval("1+1; nil")} assert_nil assert_warning('') {eval("1.+(1); nil")} @@ -884,10 +883,10 @@ x = __ENCODING__ assert_nil assert_warning(useless_use) {eval("::TestParse; nil")} assert_nil assert_warning(useless_use) {eval("x..x; nil")} assert_nil assert_warning(useless_use) {eval("x...x; nil")} - assert_nil assert_warning(unused) {eval("self; nil")} - assert_nil assert_warning(unused) {eval("nil; nil")} - assert_nil assert_warning(unused) {eval("true; nil")} - assert_nil assert_warning(unused) {eval("false; nil")} + assert_nil assert_warning(useless_use) {eval("self; nil")} + assert_nil assert_warning(useless_use) {eval("nil; nil")} + assert_nil assert_warning(useless_use) {eval("true; nil")} + assert_nil assert_warning(useless_use) {eval("false; nil")} assert_nil assert_warning(useless_use) {eval("defined?(1); nil")} assert_equal 1, x diff --git a/test/ruby/test_pattern_matching.rb b/test/ruby/test_pattern_matching.rb index b761909913..8e2806581c 100644 --- a/test/ruby/test_pattern_matching.rb +++ b/test/ruby/test_pattern_matching.rb @@ -1161,7 +1161,7 @@ END end end - bug18890 = assert_warning(/(?:.*:[47]: warning: unused literal ignored\n){2}/) do + bug18890 = assert_warning(/(?:.*:[47]: warning: possibly useless use of a literal in void context\n){2}/) do eval("#{<<~';;;'}") proc do |i| case i |