Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array(T | Array[T]) not well handled #1874

Open
HoneyryderChuck opened this issue Jun 7, 2024 · 2 comments
Open

Array(T | Array[T]) not well handled #1874

HoneyryderChuck opened this issue Jun 7, 2024 · 2 comments

Comments

@HoneyryderChuck
Copy link
Contributor

Given a variable typed as smth or collection of smth, Array(a) does not spread correctly:

# a: Symbol | Array[Symbol]
Array(a).each do |el|
# el is typed as Symbol | Array[Symbol], instead of Symbol
@ParadoxV5
Copy link
Contributor

ParadoxV5 commented Jun 7, 2024

The problem is once again

rbs/core/kernel.rbs

Lines 442 to 444 in 45b34bd

def self?.Array: (nil) -> []
| [T] (array[T] | _ToA[T] array_like) -> Array[T]
| [T] (T ele) -> [T]

Contray to our expectation, former overloads does not narrow latter overloads.

We’d have to change that to something like [T] (T ele) -> [T] | Array[untyped], yet this still won’t help with the topic without more efforts done by the type checkers.

@soutaro
Copy link
Member

soutaro commented Jun 14, 2024

Confirmed. The type of Array(a) is Array[Symbol | Array[Symbol]] where it is expected to be Array[Symbol].
Not sure if I can fix the problem... 😫

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants