Skip to content

[SR-16108] Inconsistency between Any.Protocol and (any Any).Type #58367

@swift-ci

Description

@swift-ci
Previous ID SR-16108
Radar None
Original Reporter templar (JIRA User)
Type Bug
Environment

Xcode Version 13.3 (13E113), playground.

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 4161fe58e12b7763211c3196a2aed02c

Issue Description:

According to the proposal, https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md#metatypes:

P.Protocol, becomes (any P).Type

also,

The protocol metatypes for Any and AnyObject are spelled (any Any).Type and (any AnyObject).Type, respectively.

However, the following code shows the two are not the same considering Any:

Int.self is Any.Protocol // false
Int.self is (any Any).Type // true <- how come?
protocol P {}
P.self is Any.Protocol // false
P.self is (any Any).Type // true <- how come?

It seems, (any Any).Type is transformed into Any.Type by the compiler.

Also, it is illegal to write something like

let something = (any Any).Type.self // error: expected ',' separator.

A same problem exists for AnyObject.

(any AnyObject).Type.self == AnyObject.Protocol.self // false <- how come?
(any AnyObject).Type.self == AnyObject.Type.self // true <- how come?

Metadata

Metadata

Assignees

No one assigned

    Labels

    compilerThe Swift compiler itselfexistentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesmetatypesFeature → types: Metatypestype checkerArea → compiler: Semantic analysistypesFeature: typesunexpected behaviorBug: Unexpected behavior or incorrect output

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions