Skip to content

Struct does initialize attributes wrong #5297

@ChrisBr

Description

@ChrisBr

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions