Project

General

Profile

Actions

Bug #21978

closed

Fix class variable cache isn't invalidated via modules

Bug #21978: Fix class variable cache isn't invalidated via modules

Added by jhawthorn (John Hawthorn) about 20 hours ago. Updated about 13 hours ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:125176]

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

Actions

Also available in: PDF Atom