Slice/array literal in for loop

Why is this syntax invalid?

for path, i in []string{"resources/wall.png", "resources/container.png", "resources/awesomeface.png"} {
   fmt.println(path)
}

I guess because the {"resources/wall.png",...} looks like the loop body.
The odin parser doesn’t really like ambiguous syntax, so if it looks at a loop and the loop body doesn’t have expressions but literals then it errs out.

The easy fix is to just wrap the literal in parens:

	for s, i in ([]string{"foo", "bar"}) {
		fmt.println(i, s)
	}
3 Likes