Confused with type erasure when working with existential type

As per the talk, we have the following example:

protocol Animal {
    associatedtype CommodityType: Food
    func produce() -> CommodityType
}

protocol Food {}

struct Farm {
    var animals: [any Animal]

    func produceCommodities() -> [any Food] {
        let produce = animals.map { animal in
            // animal has type Animal
            animal.produce()
        }

        // produce has type [Food]
        return produce
    }
}

In the video(03:51) the lecturer goes on to explain that the type of animal is any Animal but when I wrote the same code I can clearly see that the type is Animal - thus what happened to the existential ? The same goes for the return type of produce - I was expecting the type of the value to be any Food but it is Food.

Anyone can explain the reason for the mismatch between what is shown in the lecture and what the compiler shows ? Using Xcode 14.2

Currently Animal and any Animal are synonyms. To quote SE-0335 Introduce existential any:

In Swift 5, anywhere that an existential type can be used today, the any keyword can be used to explicitly denote an existential type

The plan is for Swift 6 to make the any required, which ‘frees up space’ for the protocol type name (Animal) to be used for other stuff. See this section of the proposal.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Confused with type erasure when working with existential type
 
 
Q