Project

General

Profile

Actions

Bug #18185

closed

BasicObject is inserted in the middle of the inheritance tree.

Added by ksss (Yuki Kurihara) about 1 month ago. Updated about 1 month ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.0dev (2021-09-22T10:04:55Z master 7c0230b05d) [arm64-darwin20]
[ruby-core:105374]

Description

t.rb

#! /usr/bin/env ruby

class Mod < Module
  module InstanceMethods
  end
  def initialize(aaa:)
    include InstanceMethods
  end
end
class Foo
  def initialize(key:)
  end
end

class Bar < Foo
  include Mod.new(aaa: 1)
end

p Bar.ancestors
p Bar.new(key: 1)

3.0.2

$ ruby -v t.rb
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [arm64-darwin20]
[Bar, #<Mod:0x000000011e82ef50>, Mod::InstanceMethods, Foo, Object, Kernel, BasicObject]
#<Bar:0x000000011e82e640>

3.1.0-dev

$ ruby -v t.rb
ruby 3.1.0dev (2021-09-22T10:04:55Z master 7c0230b05d) [arm64-darwin20]
[Bar, #<Mod:0x000000010321f558>, Mod::InstanceMethods, BasicObject, Foo, Object, Kernel, BasicObject]
t.rb:20:in `initialize': wrong number of arguments (given 1, expected 0) (ArgumentError)
    from t.rb:20:in `new'
    from t.rb:20:in `<main>'

I found this problem when running the Rails db:schema:loadtask.
Upon closer inspection, the following code seemed to be causing the problem.

https://github.com/rails/rails/blob/e44ce53f78fb376d8d48145e2319204a1a2ebfc9/activemodel/lib/active_model/type/date_time.rb#L8-L10
https://github.com/rails/rails/blob/e44ce53f78fb376d8d48145e2319204a1a2ebfc9/activemodel/lib/active_model/type/helpers/accepts_multiparameter_time.rb

t.rb is a small reproduction of this problem.
This problem does not seem to occur in v3.0.2 of ruby.


Related issues

Related to Ruby master - Bug #18182: wrong number of arguments (given 1, expected 0) (ArgumentError) since 178ee1e801acb33d13b3e8a630f6ca4926c68fbcClosedActions

Updated by ufuk (Ufuk Kayserilioglu) about 1 month ago

This looks like a duplicate of https://bugs.ruby-lang.org/issues/18182 to me. Granted, this has more info about what is going wrong in this situation, though.

Updated by jeremyevans0 (Jeremy Evans) about 1 month ago

Thank you for providing a simple reproducible example. I've submitted a pull request to fix this issue: https://github.com/ruby/ruby/pull/4886

Actions #3

Updated by jeremyevans0 (Jeremy Evans) about 1 month ago

  • Related to Bug #18182: wrong number of arguments (given 1, expected 0) (ArgumentError) since 178ee1e801acb33d13b3e8a630f6ca4926c68fbc added
Actions #4

Updated by nobu (Nobuyoshi Nakada) about 1 month ago

  • Status changed from Open to Closed

Applied in changeset git|65285bf673914424e960671d1d35e357c455985e.


Consider modified modules initialized [Bug #18185]

Actions

Also available in: Atom PDF