[前][次][番号順一覧][スレッド一覧]

ruby-changes:73813

From: eileencodes <ko1@a...>
Date: Sat, 1 Oct 2022 05:58:16 +0900 (JST)
Subject: [ruby-changes:73813] 0ab0229c11 (master): Fix frozen object inspect

https://git.ruby-lang.org/ruby.git/commit/?id=0ab0229c11

From 0ab0229c1162308509b36cafbf6eaafd7ae054d7 Mon Sep 17 00:00:00 2001
From: eileencodes <eileencodes@g...>
Date: Fri, 30 Sep 2022 15:37:18 -0400
Subject: Fix frozen object inspect

In the rails/rails CI build for Ruby master we found that some tests
were failing due to inspect on a frozen object being incorrect.

An object's instance variable count was incorrect when frozen causing
the object's inspect to not splat out the object.

This fixes the issue and adds a test for inspecting frozen objects.

Co-Authored-By: Jemma Issroff <jemmaissroff@g...>
Co-Authored-By: Aaron Patterson <tenderlove@r...>
---
 shape.c                  | 3 +--
 test/ruby/test_object.rb | 9 +++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/shape.c b/shape.c
index ba195c3c96..a6a5adf854 100644
--- a/shape.c
+++ b/shape.c
@@ -149,13 +149,12 @@ get_next_shape_internal(rb_shape_t* shape, ID id, VALUE obj, enum shape_type sha https://github.com/ruby/ruby/blob/trunk/shape.c#L149
                         }
                         break;
                     case SHAPE_IVAR_UNDEF:
+                    case SHAPE_FROZEN:
                         new_shape->iv_count = new_shape->parent->iv_count;
                         break;
                     case SHAPE_ROOT:
                         rb_bug("Unreachable");
                         break;
-                    case SHAPE_FROZEN:
-                        break;
                 }
 
                 rb_id_table_insert(shape->edges, id, (VALUE)new_shape);
diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb
index 83208bbcdb..a9d5d4b13e 100644
--- a/test/ruby/test_object.rb
+++ b/test/ruby/test_object.rb
@@ -993,4 +993,13 @@ class TestObject < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_object.rb#L993
       end
     EOS
   end
+
+  def test_frozen_inspect
+    obj = Object.new
+    obj.instance_variable_set(:@a, "a")
+    ins = obj.inspect
+    obj.freeze
+
+    assert_equal(ins, obj.inspect)
+  end
 end
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]