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

[SwiftInterfaceParser] Parser can't handle the swift 'any' syntax #773

@stephen-hawley

Description

@stephen-hawley

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions