Bug #21978
closedFix class variable cache isn't invalidated via modules
Description
module M; @@x = 1; end
class A; end
class B < A
include M
def self.x; @@x; end
end
B.x # warm cache
A.class_variable_set(:@@x, 2)
B.x
The last call to B.x should fail with Should raise: class variable @@x of M is overtaken by A (RuntimeError), but has been returning 1 since since ruby-3.2.0-preview3.
It should be solvable by by bumping the global state counter more aggressively: https://github.com/ruby/ruby/pull/16551
Updated by jhawthorn (John Hawthorn) about 10 hours ago
- Status changed from Open to Closed
Applied in changeset git|dd3542a0cd00b40d406763e85ac12a1086bab682.
Fix class variable cache not invalidated by class_variable_set
The previous invalidation walked subclasses but missed cvars from
included modules, and skipped invalidation when creating a new cvar on
modules entirely. Always invalidate when a new class variable is
created, since this should be relatively rare.
We previously bumped the global state on any module inclusion, which
should be far more common than this.
[Bug #21978]