Protocol extension with default implementation and default parameters leads to segmentation fault

Yes, as you surmised, your default implementation is also used to satisfy the protocol requirement so the compiler doesn't require you to implement it in conforming types and you end up with infinite recursion.

There is no good solution for this case currently as far as I am aware.

You either need to manually make sure that each conforming type implements the protocol requirement or use different names for the protocol requirement and the default implementation with the default argument (or avoid the default argument entirely or move it to a wrapper).


There have been several previous discussions about allowing default arguments in protocol requirements directly (example) which would sidestep this issue.

Alternatively if you had to manually mark implementations of protocol requirements, the default implementation here could avoid that so conforming types would still be required to add the requirement themselves. But that would require a massive source breaking change, and seems rather unlikely to happen. [See here] (https://forums.swift.org/t/keyword-for-protocol-methods) for an example of a similar discussion.

Perhaps the most realistic workaround would be an attribute that could be used on the default implementation to mark it as not satisfying the protocol requirement. For example, a @_notImplementing companion to @_implements.