t.0, t.1, ... access a tuple's elements, numbered from 0. The index is past the end of the
tuple, or the value isn't a tuple at all.
Wrong#
fn second(p: (int, str)): str = p.2Fixed#
fn second(p: (int, str)): str = p.1Common causes#
- Counting tuple elements from 1 instead of 0.
- A numeric field on a struct or list: use
xs[0]for lists and named fields for structs. - Destructuring is often clearer:
let (n, s) = p.