close
Skip to content

def initialize is duplicated in RBS output when redefined inside a Struct.new block #458

@sinsoku

Description

@sinsoku

Steps to reproduce

Analyze the following file with TypeProf.

Point = Struct.new(:x, :y) do
  def initialize(x = 0, y = 0)
    super
  end
end
Point.new
Point.new(3, 4)

Expected behavior

The initialize defined inside the block should override the one auto-generated by Struct.new. The RBS output should contain only one initialize:

class Point
  def x: -> Integer
  def x=: (untyped) -> untyped
  def y: -> Integer
  def y=: (untyped) -> untyped
  def initialize: (?Integer, ?Integer) -> void
  def self.[]: (?Integer, ?Integer) -> Point
end

Actual behavior

$ bin/typeprof reproduce.rb
# TypeProf 0.32.0

# reproduce.rb
class Point
  def x: -> Integer
  def x=: (untyped) -> untyped
  def y: -> Integer
  def y=: (untyped) -> untyped
  def initialize: (Integer, Integer) -> void
  def self.[]: (Integer, Integer) -> Point
  def initialize: (?Integer, ?Integer) -> void
end

def initialize appears twice. rbs parse accepts it, but rbs validate rejects it:

$ rbs -I out.rbs validate
E, [2026-05-25T22:24:05.802363 #47971] ERROR -- rbs: out.rbs:9:2...9:44: ::Point#initialize has duplicated definitions in out.rbs:11:2...11:46 (RBS::DuplicatedMethodDefinitionError)

    def initialize: (Integer, Integer) -> void
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

System configuration

Ruby version: ruby 4.0.5
TypeProf version: 0.32.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions