Skip to content

Frozen Struct can be modified #3850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nevans opened this issue May 7, 2025 · 1 comment
Open

Frozen Struct can be modified #3850

nevans opened this issue May 7, 2025 · 1 comment
Assignees

Comments

@nevans
Copy link

nevans commented May 7, 2025

It looks like TruffleRuby isn't fully freezing struct objects. Here's a script to demonstrate expected and actual behavior:

#!/usr/bin/env ruby

puts ?=*72
puts "Ruby Engine:   #{RUBY_ENGINE} #{RUBY_ENGINE_VERSION}"

MyStruct = Struct.new(:a, :b)
struct   = MyStruct.new(1, 2)

puts "Before freeze: %p" % [struct]
struct.freeze
puts "After freeze:  %p" % [struct]
begin
  struct.a = :wat?
  struct.b = :how!
rescue FrozenError => err
  puts "Modify error:  %s" % [err]
end
puts "After attempt: %p" % [struct]
puts "Truly frozen?: %p" % [struct.frozen?]

__END__
$ ruby test.rb && RBENV_VERSION=truffleruby-24.2.0 ruby test.rb
========================================================================
Ruby Engine:   ruby 3.4.2
Before freeze: #<struct MyStruct a=1, b=2>
After freeze:  #<struct MyStruct a=1, b=2>
Modify error:  can't modify frozen MyStruct: #<struct MyStruct a=1, b=2>
After attempt: #<struct MyStruct a=1, b=2>
Truly frozen?: true
========================================================================
Ruby Engine:   truffleruby 24.2.0
Before freeze: #<struct MyStruct a=1, b=2>
After freeze:  #<struct MyStruct a=1, b=2>
After attempt: #<struct MyStruct a=:wat?, b=:how!>
Truly frozen?: true
@andrykonchin
Copy link
Member

Thank you for the report, we'll look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants