Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-4500] Wrong compiler error with @autoclosure parameter #47077

Closed
swift-ci opened this issue Apr 5, 2017 · 1 comment
Closed

[SR-4500] Wrong compiler error with @autoclosure parameter #47077

swift-ci opened this issue Apr 5, 2017 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 5, 2017

Previous ID SR-4500
Radar rdar://problem/31459424
Original Reporter amarcadet (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate

Attachment: Download

Environment

Mac OS Sierra 10.12.2 (16C67)
Xcode 8.3 (8E162)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 7f09d8ea61b526e97fbbd84ca56b5f2c

duplicates:

Issue Description:

The compiler returns false error when giving an @autoclosure parameter that could throw.

See projet in attachement, the bug is illustrated in SampleTests/SampleSpec.swift.

import Quick
import Nimble
@testable import Sample

class SampleSpec: QuickSpec {
    
    override func spec() {
        
        describe("what looks like a bug") {
            
            // this version does not compile
            
            let closureWithoutCatch = {
                let object = MyClass()
                
                // expect takes an @autoclosure as its first parameter
                expect(try object.functionThatThrow()).to(throwError())
            }
            
            // swiftc: Invalid conversion from throwing function of type '() throws -> ()' to non-throwing function type '() -> Void'
            it("generates a compiler error", closure: closureWithoutCatch)
            
            
            
            // this version compile but emits a warning that makes no sense considering the previous error
            
            let closureWithCatch = {
                let object = MyClass()
                do {
                    expect(try object.functionThatThrow()).to(throwError())
                } catch {
                    // swiftc: 'catch' block is unreachable because no errors are thrown in 'do' block
                }
            }
            
            it("generates a compiler warning", closure: closureWithCatch)
            
            
            
            // with a func the compiler raises no warning nor error
            
            it("just works", closure: closureAsFunc)
            
        }
        
    }
    
    func closureAsFunc() {
        let object = MyClass()
        expect(try object.functionThatThrow()).to(throwError())
    }
    
}
@jckarter
Copy link
Member

jckarter commented Apr 5, 2017

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

2 participants