`[key]value` map can cause runtime network errors

map access is [comparable]value
map definition/allocation is [key]value where key:comparable, value:any

same as

variable definition/allocation = MyVar:t where t:type
variable comparison = MyVar:comparable

it fails comparison because are not the same and comparable that provides that check, but does not allow allocation since the type is strict

The map query is an access+comparison and not allocating any value to it for checking type safety. That’s why allocating is an error and accessing just fails. Now, using a non-comparable value as key for access will give an error since it can’t be compared

The same with the if example, setting any var must match type, but comparing equality just needs both to be comparable, even if they would always fail. (And if you use any non comparable type, will also prevent from comparing in if statements)

(The warning also shows when you don’t provide any key at all during query on a map, since the query will also fail when nothing to be compared)

I agree that mismatching types may have no use case currently (unless considering some subclass and inheritance, idk…), and I also agree that if that’s not something related to future plans, it makes sense to be more strict and actually giving compile errors to the user instead of just warnings to improve development workflow

1 Like