You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Per the thread here: SE-0352 allows the implicit opening of existentials only when the generic type occurs exactly once in the function signature. In the sample code from the thread's first post, the init of S is implicitly using the generic type twice.
protocolP{associatedtypeAfunc getA()->A}structS<T:P>{vars:T}func testOpenSimple(p:anyP){let _ =S(s: p)// **error**, Type 'any P' cannot conform to 'P'}
An alternative approach was proposed here by @jckarter that involves a static factory method that returns the S as a protocol existential or opaque return type.
Applying this approach still yields the same error Type 'any P' cannot conform to 'P' and @jckarter thought it seemed like a bug.
To Reproduce
Attempt to run the following Swift code in a Playground with Xcode 14 beta 2 (Swift 5.7)
protocolP{associatedtypeAfunc getA()->A}protocolQ{}structS<T:P>:Q{vars:Tstaticfunc make(s:T)->someQ{returnS(s: s)}}func testOpenSimple(p:anyP){letq=S.make(s: p)// q has type `any Q`}
Expected behavior
Should build successfully and allow the initialization of S through the factory method resulting in an instance of any Q living in q
Screenshots
Environment (please complete the following information):
OS: [e.g. macOS 11.0] macOS 12.4/iOS 16.0
Xcode Version/Tag/Branch: 14 beta 2
Additional context
The text was updated successfully, but these errors were encountered:
eito
added
the
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
label
Jul 1, 2022
Describe the bug
Per the thread here: SE-0352 allows the implicit opening of existentials only when the generic type occurs exactly once in the function signature. In the sample code from the thread's first post, the init of
S
is implicitly using the generic type twice.An alternative approach was proposed here by @jckarter that involves a static factory method that returns the
S
as a protocol existential or opaque return type.Applying this approach still yields the same error
Type 'any P' cannot conform to 'P'
and @jckarter thought it seemed like a bug.To Reproduce
Expected behavior
Should build successfully and allow the initialization of
S
through the factory method resulting in an instance ofany Q
living inq
Screenshots
Environment (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: