@@ -1684,8 +1684,9 @@ types, then the generic code can only use the input values from the current
16841684isolation domain. These generic APIs can safely accept isolated conformances
16851685and call protocol requirement as long as the caller is on the same global
16861686actor that the conformance is isolated to. The following code has a protocol
1687- ` P ` , a class ` C ` with a main-actor isolated conformance to ` P ` , and two
1688- call-sites to a generic method that accepts ` some P ` :
1687+ ` P ` , a class ` C ` with a main-actor isolated conformance to ` P ` , and
1688+ call-sites to the ` P.perform ` requirement from a main-actor
1689+ task and a concurrent task:
16891690
16901691``` swift
16911692protocol P {
@@ -1701,22 +1702,27 @@ func perform(_ p: some P) {
17011702Task { @MainActor in
17021703 let c = C ()
17031704 perform (c)
1705+
1706+ let a: any P = c
1707+ a.perform ()
17041708}
17051709
17061710Task { @concurrent in
17071711 let c = C ()
17081712 perform (c) // Error
1713+
1714+ let a: any P = c // Error
1715+ a.perform ()
17091716}
17101717```
17111718
1712- The above code calls ` perform `
1713- and provides an argument with a main-actor isolated conformance to ` P ` .
1714- Calling ` perform ` from a main actor task
1719+ Calling ` P.perform ` in generic code and on an ` any P ` type
1720+ from a main actor task
17151721is safe because it matches the isolation of the conformance.
1716- Calling ` perform ` from a concurrent task
1717- results in an error,
1718- because it would allow calling the main actor isolated implementation of ` perform `
1719- from outside the main actor.
1722+ Calling ` P. perform` in generic code and on an ` any P ` type
1723+ from a concurrent task results in an error,
1724+ because it would allow calling the main actor isolated implementation
1725+ of ` P.perform ` from outside the main actor.
17201726
17211727Generic code can check whether a value conforms to a protocol
17221728through dynamic casting.
0 commit comments