Closed tristanlabelle closed 3 weeks ago
To more clearly call out when giving up on error handling.
For get/set properties:
var property: T { get throws }
func property(_ value: T) throws
var property_: T! { get set }
The first two are not ambiguous even if the property type is a closure:
class Foo<PropertyType> { var property: PropertyType { get throws { fatalError() } } func property(_ value: PropertyType) throws { fatalError() } var property_: PropertyType { get { fatalError() } set { fatalError() } } } var fooOfInt = Foo<Int>() _ = try fooOfInt.property try fooOfInt.property(fooOfInt.property) fooOfInt.property_ = 42 typealias Callable = () -> Void var fooOfCallable = Foo<Callable>() _ = try fooOfCallable.property try fooOfCallable.property() try fooOfCallable.property {} try fooOfCallable.property(fooOfCallable.property) fooOfCallable.property_ = {} typealias Func = (Int) -> Void var fooOfFunc = Foo<Func>() _ = try fooOfFunc.property try fooOfFunc.property(42) try fooOfFunc.property { _ in } try fooOfFunc.property(fooOfFunc.property) fooOfFunc.property_ = { _ in }
To more clearly call out when giving up on error handling.
For get/set properties:
var property: T { get throws }
(throwing getter)func property(_ value: T) throws
(throwing setter)var property_: T! { get set }
(fatalerror'ing, with implicitly unwrapped optionals)The first two are not ambiguous even if the property type is a closure: