Array indices in Turf have to be plain integers – things like 0, 1, 2, and so on. If you try to use a decimal number, a string, a bool, or anything else as the position inside the square brackets, the compiler stops you here.
immut primes: int[3] = [2, 3, 5];mut i: int = 1;mut val: int = primes[i]; // correct -- 'i' is a whole numberIf you use something that isn’t a whole number:
mut d: double = 1.0;mut val: int = primes[d]; // 'd' is a double, not an intEven though 1.0 looks like it obviously means index 1, Turf won’t guess for you – it wants you to be explicit, since not every double cleanly represents a whole number (what would primes[1.5] even mean?).
If the value you have really is meant to be a whole number, convert it first with to int:
mut val: int = primes[d to int];A char is not allowed as an index either – a character is a letter, not a position. If you want its character code (say, to count how often each letter appears), convert it explicitly:
mut code: int = (word[i] to int);counts[code] = counts[code] + 1;Once the value you’re indexing with is a genuine int, this error goes away. This one usually shows up early on, right around when you’re first mixing doubles and array indices together – a quick to int sorts it out.
Run turf --explain E002 in a terminal to read this again.