Skip to content
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

Inconsistencies with MRI: FrozenError (can't modify frozen array) #5160

Closed
splattael opened this issue May 9, 2018 · 2 comments
Closed

Inconsistencies with MRI: FrozenError (can't modify frozen array) #5160

splattael opened this issue May 9, 2018 · 2 comments
Milestone

Comments

@splattael
Copy link
Contributor

Environment

  • jruby -v: jruby 9.2.0.0-SNAPSHOT (2.5.0) 2018-05-09 89183d0 OpenJDK 64-Bit Server VM 25.162-b12 on 1.8.0_162-8u162-b12-1~deb9u1-b12 [linux-x86_64]
  • Operating system and platform uname -a: Linux toshi 4.9.0-0.bpo.2-amd64 #1 SMP Debian 4.9.18-1~bpo8+1 (2017-04-10) x86_64 GNU/Linux

Given code

a = [].freeze
a << 1

Expected Behavior

In MRI it's

FrozenError (can't modify frozen Array)

Actual Behavior

FrozenError (can't modify frozen array)

Note the lowercase array.

Possible references to other issues

@enebo enebo closed this as completed in a10ae0a May 9, 2018
@enebo enebo added this to the JRuby 9.2.0.0 milestone May 9, 2018
@enebo
Copy link
Member

enebo commented May 9, 2018

@splattael did this happen to cause something to fail? We are happy to correct this (and this fix fixed a second issue), but did something fail due to the wrong string 'array'?

@splattael
Copy link
Contributor Author

@enebo Yay, thanks for fixing! 💜

Yes, it caused a test failure which matched the exact error message when using Dry::Struct::Value.

It was something along these lines:

require "dry/struct"
require "dry/types"
require "minitest/autorun"

class Image < Dry::Struct::Value
  attribute :sizes, Array
end

class ImageTest < MiniTest::Test
  def test_immutable
    image = Image.new(sizes: %w[100x100])

    e = assert_raises do
      image.sizes << "200x200"
    end

    assert_equal "can't modify frozen Array", e.message
  end
end

On JRuby it failed with:

Run options: --seed 61393

# Running:

F

Finished in 0.022419s, 44.6049 runs/s, 89.2098 assertions/s.

  1) Failure:
ImageTest#test_immutable [foo2.rb:17]:
Expected: "can't modify frozen Array"
  Actual: "can't modify frozen array"

1 runs, 2 assertions, 1 failures, 0 errors, 0 skips

As a workaround we do:

...
    assert_equal "can't modify frozen array", e.message.downcase
...

Again, thanks for your blazing fast fix 🤓

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

No branches or pull requests

2 participants