summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--enumerator.c1
-rw-r--r--test/ruby/test_enumerator.rb5
2 files changed, 6 insertions, 0 deletions
diff --git a/enumerator.c b/enumerator.c
index 54cbdc4..aa96185 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -1178,6 +1178,7 @@ generator_init(VALUE obj, VALUE proc)
{
struct generator *ptr;
+ rb_check_frozen(obj);
TypedData_Get_Struct(obj, struct generator, &generator_data_type, ptr);
if (!ptr) {
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb
index 07f10dd..e3270f3 100644
--- a/test/ruby/test_enumerator.rb
+++ b/test/ruby/test_enumerator.rb
@@ -419,6 +419,11 @@ class TestEnumerator < Test::Unit::TestCase
a = []
assert_equal(:foo, g2.each {|x| a << x })
assert_equal([1, 2, 3], a)
+
+ g.freeze
+ assert_raise(RuntimeError) {
+ g.__send__ :initialize, proc { |y| y << 4 << 5 }
+ }
end
def test_generator_args