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

Strict include/delete element types #835

Merged
merged 1 commit into from Dec 2, 2021
Merged

Strict include/delete element types #835

merged 1 commit into from Dec 2, 2021

Conversation

soutaro
Copy link
Member

@soutaro soutaro commented Dec 1, 2021

RBS has provided a method type of include?/delete with untyped.

class Array[Elem]
  def include?: (untyped) -> bool   # Allows passing object of unrelated types.
end

This is more compatible with Ruby runtime behavior.

a = [1, 2, 3]      # RBS assumes the `a` has type of `Array[Integer]`
a.include?("1")    # Ruby evaluates this line without an error, but returns false.

I have found that limiting the type of argument here makes more sense to find possible bugs, and want to change the type.

This is an example of the type error: Parser::KEYWORDS is Hash[String, bot], and passing a Symbol to include? always returns false, which is not what I want to do here.

@ksss
Copy link
Collaborator

ksss commented Dec 1, 2021

Is this a same problem?
#814

@soutaro
Copy link
Member Author

soutaro commented Dec 1, 2021

@ksss Yes, I changed my opinion... And I have to fix the type of #count too.

@soutaro soutaro merged commit 9f10d0f into master Dec 2, 2021
@soutaro soutaro deleted the include-type branch December 2, 2021 07:22
@ksss
Copy link
Collaborator

ksss commented Dec 3, 2021

Thank you for your consideration of my opinion.

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

Successfully merging this pull request may close these issues.

None yet

2 participants