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-14606] could we improve failure-to-handle-throw error message for closures? #56958

Open
mattneub opened this issue May 7, 2021 · 1 comment
Labels
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement type checker Area → compiler: Semantic analysis

Comments

@mattneub
Copy link

mattneub commented May 7, 2021

Previous ID SR-14606
Radar rdar://problem/77673456
Original Reporter @mattneub
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, DiagnosticsQoI, TypeChecker
Assignee None
Priority Medium

md5: ae4b58ef6155521cb127b6974edc591b

Issue Description:

First, here's a good error message:

func thrower() throws -> () {
    // doesn't matter what we put here
}
func f() -> () {
    try thrower()
}
// errors thrown from here are not handled

Yup, just about anyone can probably understand that. I wouldn't mind if it were more explicit; there are basically four solutions (`throws`, `do/catch`, `try?`, and `try!`) and a FixIt suggesting them would be great, but it's clear enough.

OK, now let's move the problem into a closure:

func doThis(f:()->()) {
    f()
}
func thrower() throws -> () {
    // doesn't matter what we put here
}
func f() {
    doThis {
        try thrower()
    }
}
// invalid conversion from throwing function of type '() throws -> ()' to non-throwing function type '() -> ()'

Experience (on Stack Overflow) shows that that just confuses people — a lot. I wonder if it might be made smart enough to say "errors thrown from here are not handled" instead? Thanks for considering this.

@typesanitizer
Copy link

@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
compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation improvement type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants