You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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".
If there are 1 or more rigid types, then (a) they must all be the same and (b) that determines the answer.
Otherwise, we take the LUB of the <= types.
Then we check that all of the rigid types equal the solution and all of the <= types can be promoted to the solution.
The text was updated successfully, but these errors were encountered:
Description
Key types of collections may be improperly promoted to types when the collection requires a lower type.
For example, in the
get
function:if we get
map:: map<i32, string>
andkey :: i64
then we’d promoteK
toi64
, 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 eitheri32
or a type that can promote toi32
.i64
is a promotion ofi32
, 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".
The text was updated successfully, but these errors were encountered: