steep icon indicating copy to clipboard operation
steep copied to clipboard

Array type conversion behaves oddly.

Open samuel-williams-shopify opened this issue 5 months ago • 1 comments

For some reason, this is fine:

if path.is_a?(Symbol)
  @path = Array(path)
else
  @path = Array(path)
end

But this fails:

@path = Array(path)

Exact error:

lib/decode/definition.rb:21:3: [error] Cannot assign a value of type `[(::Symbol | ::Array[::Symbol])]` to a variable of type `::Array[::Symbol]`
│   [(::Symbol | ::Array[::Symbol])] <: ::Array[::Symbol]
│     (::Symbol | ::Array[::Symbol]) <: ::Symbol
│       ::Array[::Symbol] <: ::Symbol
│         ::Object <: ::Symbol
│           ::BasicObject <: ::Symbol
│
│ Diagnostic ID: Ruby::IncompatibleAssignment
│
└                       @path = Array(path)
     ~~~~~~~~~~~~~~~~~~~

The expectation is that path is Symbol | Array[Symbol]. Let me know if you need more details.

samuel-williams-shopify avatar Jul 20 '25 10:07 samuel-williams-shopify

This is most likely the root cause: https://github.com/ruby/rbs/issues/1874

vpellan avatar Oct 30 '25 15:10 vpellan