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
swift-ci opened this issue
Aug 28, 2019
· 2 comments
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler in itselffeatureA feature request or implementation
Let the standard library protocols with automatic conformance (SLPwAC) be defined as those matching protocols from the Standard Library (that's Equatable, Hashable, Encodable, and Decodable as of this writing)
For the SLPwAC, said automation is implicit. You just have to declare the conformance and not bother adding any corresponding members. But if a different protocol has a members defined in an extension that match the signature of members from the SLPwAC, then automatically-defined implicit member definitions are cancelled and the extension's code is used, even if it customizes the member in a way the user doesn't want.
(It doesn't matter if MyType adds its Equatable conformance in the primary definition or in an extension block. It doesn't matter if Sucker refines Equatable or not.)
If you change the compilation test to true, then "Sucker" will be printed.
I suggest that we add an explicit declaration in nominal types that posts the desire to use the compiler-generated versions of SLPwAC members, with the same precedence as an explicitly written member in the target type (which out-prioritizes any imported definitions from protocols).
The current behavior is definitely the design provided by the proposals, but it's caused other problems too like SR-9425. Regardless, any change would have to go through the Swift Evolution Process.
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler in itselffeatureA feature request or implementation
Additional Detail from JIRA
md5: b79cf4dfcae039d527156fa5f643306d
relates to:
Issue Description:
Let the standard library protocols with automatic conformance (SLPwAC) be defined as those matching protocols from the Standard Library (that's
Equatable
,Hashable
,Encodable
, andDecodable
as of this writing)For the SLPwAC, said automation is implicit. You just have to declare the conformance and not bother adding any corresponding members. But if a different protocol has a members defined in an extension that match the signature of members from the SLPwAC, then automatically-defined implicit member definitions are cancelled and the extension's code is used, even if it customizes the member in a way the user doesn't want.
(It doesn't matter if
MyType
adds itsEquatable
conformance in the primary definition or in an extension block. It doesn't matter ifSucker
refinesEquatable
or not.)If you change the compilation test to
true
, then "Sucker" will be printed.I suggest that we add an explicit declaration in nominal types that posts the desire to use the compiler-generated versions of SLPwAC members, with the same precedence as an explicitly written member in the target type (which out-prioritizes any imported definitions from protocols).
We could depreciate the current implicit behavior and maybe end it later.
The text was updated successfully, but these errors were encountered: