-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itself
Description
| Previous ID | SR-2324 |
| Radar | rdar://problem/27795901 |
| Original Reporter | ilijatovilo (JIRA User) |
| Type | Bug |
| Status | Resolved |
| Resolution | Done |
Environment
OSX 10.11.6 (15G31)
MacBook Pro (Retina, Mid 2012)
Version 8.0 beta 5 (8S193k)
Toolchain: Swift Development Snapshot 2016-08-07 (a)
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Compiler |
| Labels | Bug |
| Assignee | @milseman |
| Priority | Medium |
md5: ab4ee203bb7d77d3976562cd10a4342c
is duplicated by:
- SR-2166 Should be able to @NoEscape a optional closure
- SR-2444 @escaping failing on optional blocks
- SR-2474 closure in protocol extension implicitly captures mutating 'self'
Issue Description:
The following code snippet doesn't work anymore in the current Swift 3 snapshot:
func takes(anOptionalClosure: (() -> Void)?) {
if let aClosure = anOptionalClosure {
aClosure()
}
}
func takes(aClosure: () -> Void) {
takes(anOptionalClosure: aClosure)
}> main.swift:18:30: Cannot convert value of type '() -> Void' to expected argument type '(() -> Void)?'
My guess is that the type checker thinks that `(() -> Void)?` is interpreted as a tuple type. But the parens are only necessary to make the closure optional. Interestingly this only happens with function types. `(String)?` e.g. type checks correctly.
The following snippet works as expected:
func takes(anOptionalClosure: (() -> Void)?) {
if let aClosure = anOptionalClosure {
aClosure()
}
}
// Hint: Added two surrounding parens to the argument type
func takes(aClosure: (() -> Void)) {
takes(anOptionalClosure: aClosure)
}rayx
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itself