Skip to content

Conversation

tk0miya
Copy link
Contributor

@tk0miya tk0miya commented Feb 11, 2025

For example, Array[Integer] can take other number types validly:

> [1, 2, 3].include? 2.0
=> true
> [1, 2, 3].include? Complex(2)
=> true
> [1, 2, 3].include? Rational(2)
=> true

refs: soutaro/steep#1482

For example, `Array[Integer]` can take other number types validly:

```
> [1, 2, 3].include? 2.0
=> true
> [1, 2, 3].include? Complex(2)
=> true
> [1, 2, 3].include? Rational(2)
=> true
```

refs: soutaro/steep#1482
@ksss
Copy link
Collaborator

ksss commented Feb 12, 2025

In reality, it seems that the == method is being used as an interface.

irb(main):005> TracePoint.new(:a_call) { |tp| p tp }.enable { [1, 2, 3].include? 2.0 }
#<TracePoint:b_call (irb):5>
#<TracePoint:c_call 'include?' (irb):5>
#<TracePoint:c_call '==' (irb):5>
#<TracePoint:c_call '==' (irb):5>
=> true

However, since == is a method of BasicObject, it applies to almost all objects.
Therefore, using untyped is fine.

@@ -2182,7 +2182,7 @@ class Array[unchecked out Elem] < Object
#
# Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
#
def include?: (Elem object) -> bool
def include?: (untyped object) -> bool
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, I thought to allow taking nil value. Therefore I changed this type as follows once:

Suggested change
def include?: (untyped object) -> bool
def include?: (Elem? object) -> bool
| (untyped object) -> false

But I noticed it does not help the numbers' case. Therefore, I used untyped here finally.

@soutaro soutaro added this to the RBS 3.9 milestone Feb 19, 2025
@soutaro
Copy link
Member

soutaro commented Feb 19, 2025

I prefer keeping the strict method type, because finding a code passing an unexpected object to include? actually helps.

Can you share the code where you want this? @tk0miya

@soutaro
Copy link
Member

soutaro commented Feb 19, 2025

Ah, soutaro/steep#1482...

%w,true,.include?(ENV['foo'])

Hmm...

@soutaro soutaro removed this from the RBS 3.9 milestone Feb 27, 2025
@soutaro
Copy link
Member

soutaro commented Feb 27, 2025

No conclusion yet, though I'm not very positive about this change.
Skipped in 3.9.

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

Successfully merging this pull request may close these issues.

3 participants