deivid-rodriguez/byebug

Hit condition cannot be set to nil despite documentation

firelizzard18 opened this issue · 0 comments

Problem description

The documentation on Breakpoint#hit_condition= indicates that nil should be a valid value. However, the implementation doesn't actually handle nil.

/*
* call-seq:
* breakpoint.hit_condition = symbol
*
* Sets the hit condition of the breakpoint which must be one of the following
* values:
*
* +nil+ if it is an unconditional breakpoint, or
* :greater_or_equal(:ge), :equal(:eq), :modulo(:mod)
*/
static VALUE
brkpt_set_hit_condition(VALUE self, VALUE value)
{
breakpoint_t *breakpoint;
ID id_value;
Data_Get_Struct(self, breakpoint_t, breakpoint);
id_value = rb_to_id(value);
if (rb_intern("greater_or_equal") == id_value || rb_intern("ge") == id_value)
breakpoint->hit_condition = HIT_COND_GE;
else if (rb_intern("equal") == id_value || rb_intern("eq") == id_value)
breakpoint->hit_condition = HIT_COND_EQ;
else if (rb_intern("modulo") == id_value || rb_intern("mod") == id_value)
breakpoint->hit_condition = HIT_COND_MOD;
else
rb_raise(rb_eArgError, "Invalid condition parameter");
return value;
}

Expected behavior

Calling bp.hit_condition=(nil) sets breakpoint->hit_condition = HIT_COND_NONE;

Actual behavior

TypeError (nil is not a symbol)

Steps to reproduce the problem

irb> require 'byebug/core'
irb> bp = Byebug::Breakpoint.add('file.rb', 1)
irb> bp.hit_condition = nil