I looked into it. Default generic arguments have not come to be. (Type inference from default expressions is related but doesn't solve this problem.)
When type is established by return value, I can't figure out how to avoid complete code duplication for overloads without introducing a useless parameter to one of the overloads.
protocol Protocol {
static func pretendThisIsMoreInteresting() -> Self
}
func function<P: Protocol>(_: Void = ()) -> P {
P.pretendThisIsMoreInteresting()
}
struct GoodDefault: Protocol {
static func pretendThisIsMoreInteresting() -> Self { .init() }
}
func function() -> GoodDefault {
function(())
}
// This is the spelling both overloads should use.
let goodDefault = function()
struct NotAGoodDefault: Protocol {
static func pretendThisIsMoreInteresting() -> Self { .init() }
}
// This is the overload using the useless default.
let notAGoodDefault: NotAGoodDefault = function()