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

bug: treat key types of collections as "rigid" #535

Open
jordanrfrazier opened this issue Jul 18, 2023 · 0 comments
Open

bug: treat key types of collections as "rigid" #535

jordanrfrazier opened this issue Jul 18, 2023 · 0 comments
Labels
bug Something isn't working sparrow

Comments

@jordanrfrazier
Copy link
Collaborator

jordanrfrazier commented Jul 18, 2023

Description
Key types of collections may be improperly promoted to types when the collection requires a lower type.

For example, in the get function:

get<K, V>(map: Map<K, V>, key: K) -> V

if we get map:: map<i32, string> and key :: i64 then we’d promote K to i64, thus changing the type of the map key, which will fail during runtime.

Expected Behavior
A possible solution is to introduce some "rigidity" to types when collection keys are concerned. In our earlier example, we should require the key input to be <= i32, meaning either i32 or a type that can promote to i32. i64 is a promotion of i32, which would mean that it is an incompatible type.

Possibly adding metadata to each type during inference indicating whether the type is promotable or not. Or, collecting multiple sets of types where one set is "rigid" and the other "promotable".

  1. If there are 1 or more rigid types, then (a) they must all be the same and (b) that determines the answer.
  2. Otherwise, we take the LUB of the <= types.
  3. Then we check that all of the rigid types equal the solution and all of the <= types can be promoted to the solution.
@jordanrfrazier jordanrfrazier added bug Something isn't working sparrow labels Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sparrow
Projects
None yet
Development

No branches or pull requests

1 participant