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

WIP - Add K/V type restrictions for Hash methods #6154

Closed

Conversation

bew
Copy link
Contributor

@bew bew commented Jun 2, 2018

This adds key/value type restrictions to most of the Hash methods.

It makes more compile error, but imo, safer/type-safe code:

h = {1 => "hello"}
h.has_key(:foo)   # previously: false      now: compile error: no overload...
h[:foo]  # previously: raise KeyError      now: compile error: no overload...

WIP: I'm fixing compiler compile error now, please wait...

@bcardiff
Copy link
Member

bcardiff commented Jun 7, 2018

@bew those restrictions are not missing. Adding them would make the API of hash a bit more pedantic specially when dealing with unions. If the key comes from a union you will need to ensure the type match before calling. And also when modules and type hierarchy are involved and the inferred type does not match what you expect. I recall going back and forth in this manner in the whiteboard.

It's true that returning always false vs not compiling seems less safety or bug prone. But in containers API I found that sometime is more a grayscale than black or white criteria.

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.

None yet

2 participants