- Proposal: SE-0159
- Authors: Brian King
- Review Manager: TBD
- Status: Awaiting review
- Bug: SR-1762
This proposal disallows the final
keyword when declaring functions in protocol
extensions.
In the current version of Swift, the final
keyword does not modify
dispatch behavior in any way, and it does not generate an error message.
This keyword has no use in Swift's current protocol model. Functions in
protocol extensions cannot be overridden and will always use direct dispatch.
This bug was listed as a Swift Evolution starter bug by the core team.
Jordan Rose described the history behind this behavior:
We originally required `final` to signify that there was no
dynamic dispatch going on. Once we started allowing protocol extension
methods to fulfill requirements, it became more confusing than useful.
If adopted, the compiler will flag the use of the final
keyword on functions
declared within a protocol extension, and emit an error or warning. This behavior
is consistent with final
use in structures and enumerations.
This change will impact source compatibility. Current use of final
in
protocol extensions will raise a compilation error and should be addressed by
source migration and fixits. When running in Swift 3 mode, a warning will be
generated instead of an error.
This proposal does not affect ABI stability.
This proposal does not affect API resilience.
There are no alternatives considered at this time.