Docs menu

E004: One of the values in your array's initializer list is the wrong type

What compiler error E004 means, and how to fix it.

An array holds one specific type of value – an int[3] holds three ints, a string[2] holds two strings, and so on. If even one value in the initializer list doesn’t match that type, Turf catches it right away instead of letting a mixed-up array sneak into your program.

Example
immut primes: int[3] = [2, 3, 5];   // correct -- every value is an int

If one of the values is the wrong type:

Example
immut primes: int[3] = [2, 3, "five"];   // "five" is a string, not an int

Turf tells you the element type the array holds and the type of the value it found, so you know what to look for when you scan the list for the odd one out.

Either side can be the mistake: the values, or the type written for the array. When every value has the same type, the hint names both fixes:

Example
mut codes: char[3] = [10, 20, 30];// Hint: Declare `codes` as `int[3]`, or convert each value with `to char`.

If the values are what you meant, change the declaration (mut codes: int[3]). If the type is, make the values that type: convert them with to where a conversion exists, or write values of that type where none does (mut flags: bool[2] = [1, 2]; needs bool values, since an int does not convert to a bool).

This is a great one to double-check whenever you’re typing out a long list of values by hand – it’s easy for one typo (like quoting a number by accident) to slip in.

Run turf --explain E004 in a terminal to read this again.

Last updated: Oct 15, 2026Edit this page on GitHub

Esc

Type to search.