Skip to content

Commit 7ad74d1

Browse files
eileencodeskddnewton
authored andcommitted
[PRISM] Implement unused block warning
Related: ruby/prism#2935
1 parent e15b454 commit 7ad74d1

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

iseq.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,6 @@ pm_iseq_new_with_opt(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpa
10301030
{
10311031
rb_iseq_t *iseq = iseq_alloc();
10321032
ISEQ_BODY(iseq)->prism = true;
1033-
ISEQ_BODY(iseq)->param.flags.use_block = true; // unused block warning is not supported yet
10341033

10351034
rb_compile_option_t next_option;
10361035
if (!option) option = &COMPILE_OPTION_DEFAULT;

prism_compile.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3825,6 +3825,7 @@ pm_compile_defined_expr0(rb_iseq_t *iseq, const pm_node_t *node, const pm_node_l
38253825
case PM_YIELD_NODE:
38263826
PUSH_INSN(ret, location, putnil);
38273827
PUSH_INSN3(ret, location, defined, INT2FIX(DEFINED_YIELD), 0, PUSH_VAL(DEFINED_YIELD));
3828+
iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
38283829
return;
38293830
case PM_SUPER_NODE:
38303831
case PM_FORWARDING_SUPER_NODE:
@@ -6962,6 +6963,9 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
69626963

69636964
PUSH_LABEL(ret, retry_label);
69646965
}
6966+
else {
6967+
iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
6968+
}
69656969

69666970
PUSH_INSN(ret, location, putself);
69676971
int flag = VM_CALL_ZSUPER | VM_CALL_SUPER | VM_CALL_FCALL;
@@ -8994,6 +8998,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
89948998
if (parameters_node->block) {
89958999
body->param.block_start = local_index;
89969000
body->param.flags.has_block = true;
9001+
iseq_set_use_block(iseq);
89979002

89989003
pm_constant_id_t name = ((const pm_block_parameter_node_t *) parameters_node->block)->name;
89999004

@@ -9549,6 +9554,10 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
95499554
pm_scope_node_destroy(&next_scope_node);
95509555
}
95519556

9557+
if (!cast->block) {
9558+
iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
9559+
}
9560+
95529561
if ((flags & VM_CALL_ARGS_BLOCKARG) && (flags & VM_CALL_KW_SPLAT) && !(flags & VM_CALL_KW_SPLAT_MUT)) {
95539562
PUSH_INSN(args, location, splatkw);
95549563
}
@@ -9681,6 +9690,7 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
96819690
}
96829691

96839692
PUSH_INSN1(ret, location, invokeblock, new_callinfo(iseq, 0, argc, flags, keywords, FALSE));
9693+
iseq_set_use_block(ISEQ_BODY(iseq)->local_iseq);
96849694
if (popped) PUSH_INSN(ret, location, pop);
96859695

96869696
int level = 0;

test/ruby/test_iseq.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,6 @@ def block_unused_method
887887
def test_unused_param
888888
a = RubyVM::InstructionSequence.of(method(:block_using_method)).to_a
889889

890-
omit 'TODO: Prism' if a.dig(4, :parser) != :"parse.y"
891-
892890
assert_equal true, a.dig(11, :use_block)
893891

894892
b = RubyVM::InstructionSequence.of(method(:block_unused_method)).to_a

0 commit comments

Comments
 (0)