-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
No type error when deleting from an array an invalid type #988
Comments
Real-life example: Consider these two functions: # Mark a register as no longer used.
def freereg(reg)
@usedregs.delete reg
end
# Free a register if it's a register item.
def ofree(maybereg)
self.freereg maybereg.reg if maybereg.is_a? Parser::RegItem
end I had originally written the second-to-last line as: self.freereg maybereg if maybereg.is_a? Parser::RegItem
|
Possible fix: change line 418 of def delete(obj : T) |
This is interesting :-) In Java for example removing an element is not restricted to a type. This is because you delete elements by equality. So, this works in Ruby (and in Crystal): a = [1, 2, 3]
a.delete 1.0
a #=> [2, 3] So I'm not sure what we should do here. This is an excellent opportunity to discuss it :-) |
@asterite Well, Ruby is duck-typed, and Java is pretty stupid. ;) I'm just saying this because I don't think anyone has ever done that intentionally, as it doesn't really serve a purpose. What would the point of it be? Just my three cents. :) |
I think I side with @kirbyfan64 here, for the sole purpose of catching type errors earlier |
I think it makes sense to put a type restriction there. The same happens with |
For hash there's #8893 |
Example:
This has caused bugs for me before.
The text was updated successfully, but these errors were encountered: