This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Description
Swift has added the any as a requirement for existential protocols (ie, protocols with no associated types).
The reasoning being that when you declare a function like this:
public protocol Talkable {
func talk () -> String
}
public func identity (a: Talkable) -> Talkable
{
return a
}
You're forcing dynamic rather than static dispatch so you should have an indication that this has an associated cost.
Therefore, this function is an exact synonym to the previous:
public func identity (a: any Talkable) -> Talkable // error: Invalid redeclaration of 'identity(a:)'
{
return a
}
Any can also be used with protocols with associated types, but oddly enough these two functions:
public func otherIdentity (a: any Equatable) -> any Equatable {
return a
}
public func otherIdentity<T:Equatable> (a: T) -> T {
return a
}
does not cause an error, so they're distinct functions.