You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attempting to create a dispatch source or I/O channel is a fallible operation. In Swift 2.2 the functions used for creating them are annotated as returning implicitly-unwrapped optionals, and nil is returned when creation fails. This can be checked for and handled appropriately.
In Swift 2.3 and 3.0 the functions/initializers are annotated as returning non-nil values, but nil can still be returned. This can be reproduced by providing invalid parameters.
The code below will run successfully under Swift 2.2, but will crash at runtime under 2.3 and 3.0 despite the lack of any forced or implicit unwrapping.
This was intentional and follows the rules established by Foundation for nullability annotation of return values.
The only time source object creation can return nil is on programmer error by passing bad input arguments that are non-sensical or contradictory (like in your example with a nonsensical signal number). It never returns nil for conditions that cannot be controlled by the programmer locally at the call site.
Similarly for dispatch_io, path-based creation requires an absolute path and so when that is not the case we treat that input as programmer error. The only other case treated this way is a bad channel type (c.f. source code, all these cases are expressed as DISPATCH_BAD_INPUT)
Additional Detail from JIRA
md5: d1490ba04e755f83c340b8874532c6bf
Issue Description:
Attempting to create a dispatch source or I/O channel is a fallible operation. In Swift 2.2 the functions used for creating them are annotated as returning implicitly-unwrapped optionals, and nil is returned when creation fails. This can be checked for and handled appropriately.
In Swift 2.3 and 3.0 the functions/initializers are annotated as returning non-nil values, but nil can still be returned. This can be reproduced by providing invalid parameters.
The code below will run successfully under Swift 2.2, but will crash at runtime under 2.3 and 3.0 despite the lack of any forced or implicit unwrapping.
The text was updated successfully, but these errors were encountered: