mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Experimental support for implicitly opening existential arguments.
When calling a generic function with an argument of existential type,
implicitly "open" the existential type into a concrete archetype, which
can then be bound to the generic type. This extends the implicit
opening that is performed when accessing a member of an existential
type from the "self" parameter to all parameters. For example:
func unsafeFirst<C: Collection>(_ c: C) -> C.Element { c.first! }
func g(c: any Collection) {
unsafeFirst(c) // currently an error
// with this change, succeeds and produces an 'Any'
}
This avoids many common sources of errors of the form
protocol 'P' as a type cannot conform to the protocol itself
which come from calling generic functions with an existential, and
allows another way "out" if one has an existention and needs to treat
it generically.
This feature is behind a frontend flag
`-enable-experimental-opened-existential-types`.
This commit is contained in:
@@ -448,6 +448,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
|
||||
Opts.EnableParameterizedProtocolTypes |=
|
||||
Args.hasArg(OPT_enable_parameterized_protocol_types);
|
||||
|
||||
Opts.EnableOpenedExistentialTypes |=
|
||||
Args.hasArg(OPT_enable_experimental_opened_existential_types);
|
||||
|
||||
Opts.EnableExperimentalDistributed |=
|
||||
Args.hasArg(OPT_enable_experimental_distributed);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user