I made a mistake in a published API that I want to deprecate.
It looks a bit like this (the generic aspect of these may not be important to the example - but the functions in question are generic in this way):
func foo<T>(_: T.Type) -> T?
being refactored to
func foo<T>(_: T.Type) throws -> T
But the problem is that the following brand of code cannot be successfully refactored to use the updated method:
guard let x = foo(T.self) else { ... } // Deprecated warning
guard let x = try? foo(T.self) else { ... } // No calls to throwing functions occur within 'try' expression
I tried something sneaky and used @_disfavoredOverload
on the deprecated method, but that put me in the opposite situation where the existing API is unreachable and instead creates a compile error to the tune of Call can throw but is not marked with 'try'
Suggestions?
Is there another way I can hint to the compiler which overload of a function I want to use. I tried adding type hints but none of my attempts have worked so far.