# \[RFC\] StaticArray doesn't do bound-checks at compile-time

**URL:** <https://forum.crystal-lang.org/t/rfc-staticarray-doesnt-do-bound-checks-at-compile-time/4425>\
**Category:** Crystal Contrib\
**Created:** [February 24, 2022, 2:58pm UTC](https://forum.crystal-lang.org/t/rfc-staticarray-doesnt-do-bound-checks-at-compile-time/4425 "2022-02-24T14:58:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [February 24, 2022, 2:58pm UTC](https://forum.crystal-lang.org/t/rfc-staticarray-doesnt-do-bound-checks-at-compile-time/4425/1 "2022-02-24T14:58:46Z")

</div>

I was playing around with static arrays today. Look at this code:

```crystal
a = StaticArray(Int32, 3).new(0)
a[10]

```

It compiles and gives a runtime error!

Compare it to this:

```crystal
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?

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [February 24, 2022, 7:18pm UTC](https://forum.crystal-lang.org/t/rfc-staticarray-doesnt-do-bound-checks-at-compile-time/4425/2 "2022-02-24T19:18:12Z")

</div>

Sounds good. Can probably reuse most of `tuple_indexer_helper`.
