diff options
author | Aaron Patterson <[email protected]> | 2025-05-20 10:15:22 -0700 |
---|---|---|
committer | Aaron Patterson <[email protected]> | 2025-05-21 09:51:32 -0700 |
commit | 6ea893f37688bafaa8145474ce754a74af5a850a (patch) | |
tree | aa19eb580443af05ac31f1dbd0fa2099ccc3f1a6 /class.c | |
parent | 511b6bcb53aec8c429d00628e7d2ba286671a4fc (diff) |
Add assertion for RCLASS_SET_PRIME_CLASSEXT_WRITABLE
When classes are booted, they should all be writeable unless namespaces
are enabled. This commit adds an assertion to ensure that classes are
writable.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/13385
Diffstat (limited to 'class.c')
-rw-r--r-- | class.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -702,7 +702,7 @@ class_alloc(VALUE flags, VALUE klass) RCLASS_PRIME_NS((VALUE)obj) = ns; // Classes/Modules defined in user namespaces are // writable directly because it exists only in a namespace. - RCLASS_SET_PRIME_CLASSEXT_WRITABLE((VALUE)obj, NAMESPACE_USER_P(ns) ? true : false); + RCLASS_SET_PRIME_CLASSEXT_WRITABLE((VALUE)obj, (NAMESPACE_USER_P(ns) || !rb_namespace_available()) ? true : false); RCLASS_SET_ORIGIN((VALUE)obj, (VALUE)obj); RCLASS_SET_REFINED_CLASS((VALUE)obj, Qnil); @@ -858,6 +858,8 @@ rb_class_new(VALUE super) RCLASS_SET_MAX_IV_COUNT(klass, RCLASS_MAX_IV_COUNT(super)); } + RUBY_ASSERT(getenv("RUBY_NAMESPACE") || RCLASS_PRIME_CLASSEXT_WRITABLE_P(klass)); + return klass; } |