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-14939] Compiler error for assumed throw that does not happen #57281

Open
swift-ci opened this issue Jul 18, 2021 · 1 comment
Open

[SR-14939] Compiler error for assumed throw that does not happen #57281

swift-ci opened this issue Jul 18, 2021 · 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

Previous ID SR-14939
Radar rdar://problem/80820406
Original Reporter fredap (JIRA User)
Type Bug
Environment

Xcode Version 12.5.1 (12E507) on the Mac

Note that this problem also happens on the Linux platform (Docker image version 5.3)

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

md5: 44803371d9ed3e7ba09dd4f36547b315

Issue Description:

I have the following code:

import Foundation
import XCTest

struct SomeError: Error { }

func throwingFunction() throws {
    throw SomeError()
}

class TestCase: XCTestCase {

    func testMethod() {
        DispatchQueue.global().async {
            do {
                XCTAssertThrowsError(try throwingFunction())
            } catch {
                // ignore
            }
        }
    }
}

This code produces a warning:

'catch' block is unreachable because no errors are thrown in 'do' block

which seems to indicate that the do block does not throw an error (which is also the expectation). The obvious solution is to remove the catch block:

class TestCase: XCTestCase {

    func testMethod() {
        DispatchQueue.global().async {
            XCTAssertThrowsError(try throwingFunction())
        }
    }
}

which then produces the error:

Invalid conversion from throwing function of type '() throws -> Void' to non-throwing function type '@convention(block) () -> Void'

which seems to indicate that XCTAssertThrowsError does throw an error

@typesanitizer
Copy link

Minimal example:

func f(_: @escaping () -> ()) {}
func g(_: @escaping @autoclosure () throws -> ()) {}
func k() throws {}

let _ = f { // invalid conversion from throwing function of type '() throws -> ()' to non-throwing function type '() -> ()'
    g(try k())
}

The problem is that @autoclosure is not handled correctly.

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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