mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Also make the titles and one line summaries a little more consistent (at least for diagnsotic groups and upcoming language features, haven't gone through the educational notes).
1.3 KiB
1.3 KiB
Existential any (ExistentialAny)
any existential type syntax.
Overview
any was introduced in Swift 5.6 to explicitly mark "existential types", i.e., abstract boxed types
that conform to a set of constraints. For source compatibility, these are not diagnosed by default
except for existential types constrained to protocols with Self or associated type requirements
(as this was introduced in the same version):
protocol Foo {
associatedtype Bar
func foo(_: Bar)
}
protocol Baz {}
func pass(foo: Foo) {} // `any Foo` is required instead of `Foo`
func pass(baz: Baz) {} // no warning or error by default for source compatibility
When enabled via -enable-upcoming-feature ExistentialAny, the upcoming language feature
ExistentialAny will diagnose all existential types without any:
func pass(baz: Baz) {} // `any Baz` required instead of `Baz`
This will become the default in a future language mode.
Migration
-enable-upcoming-feature ExistentialAny:migrate
Enabling migration for ExistentialAny adds fix-its that prepend all existential types with any
as required. No attempt is made to convert to generic (some) types.