Use RTEST and add test for GH-6832

Technically we shouldn't see Qfalse now, but RTEST also compiles down to
just one branch anyways. Pretty contrived issue, but easy to fix.
This commit is contained in:
Alan Wu 2022-11-30 15:04:31 -05:00
Родитель 4b9d10b833
Коммит 5752d11f1f
2 изменённых файлов: 9 добавлений и 1 удалений

Просмотреть файл

@ -48,7 +48,7 @@ struct_ivar_get(VALUE c, ID id)
for (;;) {
c = rb_class_superclass(c);
if (c == 0 || c == rb_cStruct || c == rb_cData || c == Qnil)
if (c == rb_cStruct || c == rb_cData || !RTEST(c))
return Qnil;
RUBY_ASSERT(RB_TYPE_P(c, T_CLASS));
ivar = rb_attr_get(c, id);

Просмотреть файл

@ -92,6 +92,14 @@ class TestMarshal < Test::Unit::TestCase
TestMarshal.instance_eval { remove_const :StructInvalidMembers }
end
def test_load_range_as_struct
assert_raise(TypeError, 'GH-6832') do
# Can be obtained with:
# $ ruby -e 'Range = Struct.new(:a, :b, :c); p Marshal.dump(Range.new(nil, nil, nil))'
Marshal.load("\x04\bS:\nRange\b:\x06a0:\x06b0:\x06c0")
end
end
class C
def initialize(str)
@str = str