Modifying frozen objects will raise `FrozenError`.
`FrozenError` is a subclass of `RuntimeError` which used to be
raised.  [Ruby2.5]
MODIFY
include/mruby.h
include/mruby.h
@@ -1164,6 +1164,7 @@ MRB_API void mrb_print_error(mrb_state *mrb);
#define E_SYNTAX_ERROR (mrb_exc_get(mrb, "SyntaxError"))
#define E_LOCALJUMP_ERROR (mrb_exc_get(mrb, "LocalJumpError"))
#define E_REGEXP_ERROR (mrb_exc_get(mrb, "RegexpError"))
+#define E_FROZEN_ERROR (mrb_exc_get(mrb, "FrozenError"))
#define E_NOTIMP_ERROR (mrb_exc_get(mrb, "NotImplementedError"))
#ifndef MRB_WITHOUT_FLOAT

MODIFY
mrbgems/mruby-string-ext/mrblib/string.rb
mrbgems/mruby-string-ext/mrblib/string.rb
@@ -95,7 +95,7 @@ class String
# "hello".lstrip! #=> nil
#
def lstrip!
- raise RuntimeError, "can't modify frozen String" if frozen?
+ raise FrozenError, "can't modify frozen String" if frozen?
s = self.lstrip
(s == self) ? nil : self.replace(s)
end
@@ -125,7 +125,7 @@ class String
# <code>nil</code> if <i>str</i> was not altered.
#
def strip!
- raise RuntimeError, "can't modify frozen String" if frozen?
+ raise FrozenError, "can't modify frozen String" if frozen?
s = self.strip
(s == self) ? nil : self.replace(s)
end
@@ -199,7 +199,7 @@ class String
# string #=> "thsa sting"
#
def slice!(arg1, arg2=nil)
- raise RuntimeError, "can't modify frozen String" if frozen?
+ raise FrozenError, "can't modify frozen String" if frozen?
raise "wrong number of arguments (for 1..2)" if arg1.nil? && arg2.nil?
if !arg1.nil? && !arg2.nil?

MODIFY
mrbgems/mruby-struct/src/struct.c
mrbgems/mruby-struct/src/struct.c
@@ -89,7 +89,7 @@ static void
mrb_struct_modify(mrb_state *mrb, mrb_value strct)
{
if (MRB_FROZEN_P(mrb_basic_ptr(strct))) {
- mrb_raise(mrb, E_RUNTIME_ERROR, "can't modify frozen struct");
+ mrb_raise(mrb, E_FROZEN_ERROR, "can't modify frozen struct");
}
mrb_write_barrier(mrb, mrb_basic_ptr(strct));

MODIFY
mrblib/10error.rb
mrblib/10error.rb
@@ -51,6 +51,9 @@ end
class NotImplementedError < ScriptError
end
+class FrozenError < RuntimeError
+end
+
class StopIteration < IndexError
attr_accessor :result
end

MODIFY
mrblib/string.rb
mrblib/string.rb
@@ -96,7 +96,7 @@ class String
#
# ISO 15.2.10.5.19
def gsub!(*args, &block)
- raise RuntimeError, "can't modify frozen String" if frozen?
+ raise FrozenError, "can't modify frozen String" if frozen?
return to_enum(:gsub!, *args) if args.length == 1 && !block
str = self.gsub(*args, &block)
return nil if str == self
@@ -159,7 +159,7 @@ class String
#
# ISO 15.2.10.5.37
def sub!(*args, &block)
- raise RuntimeError, "can't modify frozen String" if frozen?
+ raise FrozenError, "can't modify frozen String" if frozen?
str = self.sub(*args, &block)
return nil if str == self
self.replace(str)

MODIFY
src/array.c
src/array.c
@@ -114,7 +114,7 @@ static void
ary_modify_check(mrb_state *mrb, struct RArray *a)
{
if (MRB_FROZEN_P(a)) {
- mrb_raise(mrb, E_RUNTIME_ERROR, "can't modify frozen array");
+ mrb_raise(mrb, E_FROZEN_ERROR, "can't modify frozen array");
}
}

MODIFY
src/class.c
src/class.c
@@ -430,9 +430,9 @@ mrb_define_method_raw(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_method_
if (MRB_FROZEN_P(c)) {
if (c->tt == MRB_TT_MODULE)
- mrb_raise(mrb, E_RUNTIME_ERROR, "can't modify frozen module");
+ mrb_raise(mrb, E_FROZEN_ERROR, "can't modify frozen module");
else
- mrb_raise(mrb, E_RUNTIME_ERROR, "can't modify frozen class");
+ mrb_raise(mrb, E_FROZEN_ERROR, "can't modify frozen class");
}
if (!h) h = c->mt = kh_init(mt, mrb);
k = kh_put(mt, mrb, h, mid);

MODIFY
src/hash.c
src/hash.c
@@ -286,7 +286,7 @@ static void
mrb_hash_modify(mrb_state *mrb, mrb_value hash)
{
if (MRB_FROZEN_P(mrb_hash_ptr(hash))) {
- mrb_raise(mrb, E_RUNTIME_ERROR, "can't modify frozen hash");
+ mrb_raise(mrb, E_FROZEN_ERROR, "can't modify frozen hash");
}
mrb_hash_tbl(mrb, hash);
}

MODIFY
src/string.c
src/string.c
@@ -494,7 +494,7 @@ static void
check_frozen(mrb_state *mrb, struct RString *s)
{
if (MRB_FROZEN_P(s)) {
- mrb_raise(mrb, E_RUNTIME_ERROR, "can't modify frozen string");
+ mrb_raise(mrb, E_FROZEN_ERROR, "can't modify frozen string");
}
}

MODIFY
src/variable.c
src/variable.c
@@ -261,7 +261,7 @@ mrb_obj_iv_set(mrb_state *mrb, struct RObject *obj, mrb_sym sym, mrb_value v)
iv_tbl *t = obj->iv;
if (MRB_FROZEN_P(obj)) {
- mrb_raisef(mrb, E_RUNTIME_ERROR, "can't modify frozen %S", mrb_obj_value(obj));
+ mrb_raisef(mrb, E_FROZEN_ERROR, "can't modify frozen %S", mrb_obj_value(obj));
}
if (!t) {
t = obj->iv = iv_new(mrb);

Modifying frozen objects will raise `FrozenError`.

`FrozenError` is a subclass of `RuntimeError` which used to be
raised.  [Ruby2.5]