Project

General

Profile

Actions

Bug #18185

closed

BasicObject is inserted in the middle of the inheritance tree.

Added by ksss (Yuki Kurihara) over 2 years ago. Updated over 2 years ago.

Status:
Closed
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 1 (0 open1 closed)

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0