#28642 and all the work that came before support a good amount of common cases. We can do better thought. Here are some example that I would like to support in the future:
- Implicit array indices. Maybe default to
u32 since I think we cast to u32 anyways?
- In
let x = 1u32 + (true ? 1 : 2), we should infer 1 and 2 to be u32.
- In
let x = [1, 2u32, 3], we should infer 1, and 3 to be u32.
- In
let x = 1; let y = x + 3u32, we should infer that x and 1 are both u32. This requires revisiting previously type checked statements.
- In
let x = 1 + 1 + 1u32, we should infer that the 1s are both u32. The problem here is that 1 + 1 is visited first and we quickly give up.
- In
for i in 0u32..4 { }, we should infer that the 4 is a u32
- In
assert_eq(1u32, 1), we should infer that the 1 is a u32.
- Mapping function such as
.set(0, 0) should work.
- More to come
I have some ideas around these but they require a bigger refactor of parts in the compiler. I think we need a way to visit a statement/expression and have the ability to visit it again when we gather more information. So, certainly a way to throw away collected errors and not always emit them in case we revisit an item again.
#28642 and all the work that came before support a good amount of common cases. We can do better thought. Here are some example that I would like to support in the future:
u32since I think we cast tou32anyways?let x = 1u32 + (true ? 1 : 2), we should infer1and2to beu32.let x = [1, 2u32, 3], we should infer1, and3to beu32.let x = 1; let y = x + 3u32, we should infer thatxand1are bothu32. This requires revisiting previously type checked statements.let x = 1 + 1 + 1u32, we should infer that the1s are bothu32. The problem here is that1 + 1is visited first and we quickly give up.for i in 0u32..4 { }, we should infer that the4is au32assert_eq(1u32, 1), we should infer that the1is au32..set(0, 0)should work.I have some ideas around these but they require a bigger refactor of parts in the compiler. I think we need a way to visit a statement/expression and have the ability to visit it again when we gather more information. So, certainly a way to throw away collected errors and not always emit them in case we revisit an item again.