show warning for unused block

With verbopse mode (-w), the interpreter shows a warning if
a block is passed to a method which does not use the given block.

Warning on:

* the invoked method is written in C
* the invoked method is not `initialize`
* not invoked with `super`
* the first time on the call-site with the invoked method
  (`obj.foo{}` will be warned once if `foo` is same method)

[Feature #15554]

`Primitive.attr! :use_block` is introduced to declare that primitive
functions (written in C) will use passed block.

For minitest, test needs some tweak, so use
ea9caafc07
for `test-bundled-gems`.
This commit is contained in:
Koichi Sasada 2024-03-27 07:29:38 +09:00
parent 515e52a0b1
commit 9180e33ca3
18 changed files with 165 additions and 13 deletions

View file

@ -201,8 +201,8 @@ location_lineno_m(VALUE self)
VALUE rb_mod_name0(VALUE klass, bool *permanent);
static VALUE
gen_method_name(VALUE owner, VALUE name)
VALUE
rb_gen_method_name(VALUE owner, VALUE name)
{
bool permanent;
if (RB_TYPE_P(owner, T_CLASS) || RB_TYPE_P(owner, T_MODULE)) {
@ -235,7 +235,7 @@ retry:
case ISEQ_TYPE_MAIN:
return ISEQ_BODY(iseq)->location.label;
case ISEQ_TYPE_METHOD:
return gen_method_name(owner, ISEQ_BODY(iseq)->location.label);
return rb_gen_method_name(owner, ISEQ_BODY(iseq)->location.label);
case ISEQ_TYPE_BLOCK:
case ISEQ_TYPE_PLAIN: {
int level = 0;
@ -269,7 +269,7 @@ static VALUE
location_label(rb_backtrace_location_t *loc)
{
if (loc->cme && loc->cme->def->type == VM_METHOD_TYPE_CFUNC) {
return gen_method_name(loc->cme->owner, rb_id2str(loc->cme->def->original_id));
return rb_gen_method_name(loc->cme->owner, rb_id2str(loc->cme->def->original_id));
}
else {
VALUE owner = Qnil;
@ -457,7 +457,7 @@ location_to_str(rb_backtrace_location_t *loc)
file = GET_VM()->progname;
lineno = 0;
}
name = gen_method_name(loc->cme->owner, rb_id2str(loc->cme->def->original_id));
name = rb_gen_method_name(loc->cme->owner, rb_id2str(loc->cme->def->original_id));
}
else {
file = rb_iseq_path(loc->iseq);