Skip to content

Nested flatten with a custom Enumerable class doesn't work #2767

@hdoan741

Description

@hdoan741

Input

→ View on sorbet.run

# typed: true
class A 
  extend T::Sig
  extend T::Generic
  include Enumerable

  Elem = type_member(fixed: String)
  
  sig { override.params(blk: T.proc.params(e: Elem).void).void }
  def each(&blk)
    T.unsafe(nil)
  end

  sig { returns(T::Array[Elem])}
  def flatten
    T.unsafe(nil)
  end
end

def main
  a = A.new
  b = [A.new, A.new]

  T.reveal_type(a.flatten)
  T.reveal_type(b.flatten)
end

Observed output

Revealed type: T::Array[A] 

Expected behavior

Revealed type: T::Array[String]

Flatten is called on subsequent objects of the collection. I'd expect that sorbet know flatten will call flatten in the custom enumerable.

See convo on slack:
https://sorbet-ruby.slack.com/archives/CJL5B3CEN/p1583892614100500

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingunconfirmedThis issue has not yet been confirmed by the Sorbet team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions