2023-10-19-a toolchain: Enumerated sequence element type annotation is invalid in very specific case

When compiling swift-png under the 2023-10-19-a toolchain, I get the following error:

// ERROR: Cannot convert sequence element type '(offset: Int, element: Range<Int>)' to expected type '(Int, Range<Int>)'
for (i, leaves):(Int, Range<Int>) in levels[8 ..< 15].enumerated()
//                                                    ^~~~~~~~~~ (here)
{
    z       += leaves.count << (6 - i)
    interior = 2 * interior - leaves.count
}

If you remove [8 ..< 15] this compiles successfully, but even more weirdly, even if you instead just let x = levels[8 ..< 15] and use x.enumerated(), it still compiles successfully... Refactoring like that definitely shouldn't be changing the validity of the code in this case.

The compilation error goes away if you add the labels to the type annotation, but that's beside the point of how weird this behaviour is.

Apologies if this is fixed in a newer toolchain, I can't download a newer one right now (time limitation). Here's a small reproducing example if anyone wants to try it out for themselves:

let y = [1, 2, 3, 4]
// Fails with same error as above
for (_, _):(Int, Int) in y[0..<1].enumerated() {}

And here's a working example (which should really be equivalent...):

let y = [1, 2, 3, 4]
let x = y[0..<1]
// Compiles successfully
for (_, _):(Int, Int) in x.enumerated() {}
4 Likes