I was playing around with static arrays today. Look at this code:
a = StaticArray(Int32, 3).new(0)
a[10]
It compiles and gives a runtime error!
Compare it to this:
a = {1, 2, 3}
a[10]
This one gives a compile-time error!
I don’t know why we didn’t do it before, but… I think we should also add a rule to the compiler to check whether the integer literal passed to StaticArray#[]
is in bounds, and otherwise give a compile-time error.
What do you think?