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

Struct does initialize attributes wrong #5297

Closed
ChrisBr opened this Issue Aug 30, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@ChrisBr
Copy link
Contributor

ChrisBr commented Aug 30, 2018

Environment

Provide at least:

  • master: 0aef1ec
  • jruby-9.2.0.0
  • jruby-9.2.1.0-dev

Expected Behavior

When prepending a module which just calls super on the Struct, the first attribute gets initialized wrong:

klass = Struct.new(:runner_type, :output_type, keyword_init: true)
# correct output
puts klass.new({}) # -> #<struct runner_type=nil, output_type=nil>

klass.prepend(Module.new {
       def initialize(**options)
          puts options.inspect
          super(options)
        end
      })

# wrong output -> runner_type is initialized to {}
puts klass.new({}) # -> #<struct runner_type={}, output_type=nil>

Actual Behavior

The output should be the same.

The second call uses https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyStruct.java#L399 instead of https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyStruct.java#L354. Looking at the code, the same initializer should be used, no?

@ChrisBr

This comment has been minimized.

Copy link
Contributor Author

ChrisBr commented Aug 30, 2018

The code is adopted from https://github.com/benchmark-driver/benchmark-driver which uses it to generate a Config struct. benchmark-driver is basically broken for JRuby because of this issue.

@enebo enebo added this to the JRuby 9.2.1.0 milestone Aug 30, 2018

@enebo enebo closed this in 26f84cc Aug 30, 2018

@ChrisBr

This comment has been minimized.

Copy link
Contributor Author

ChrisBr commented Aug 30, 2018

Tested the fix, works for me! Thanks for the quick fix ❤️

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