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-14503] Improve diagnostic on using try on the immediate RHS of an operator #56855

typesanitizer opened this issue Apr 17, 2021 · 1 comment


Copy link

@typesanitizer typesanitizer commented Apr 17, 2021

Previous ID SR-14503
Radar rdar://problem/76786101
Original Reporter @typesanitizer
Type Improvement
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Improvement, DiagnosticsQoI
Assignee None
Priority Medium

md5: aa7426c82efcb81c25f87e34587a5cbb

Issue Description:

func f() throws -> Int { 3 }
func g() throws {
    _ = 3 + try f() // error: 'try' cannot appear to the right of a non-assignment operator
   _ = 3 + (try f()) // OK

The diagnostic wording is not quite accurate. In the second line, the try is still on the right of a non-assignment operator and that's alright, it is not on the immediate right.

Maybe we should use "immediate right" instead? I'm not sure if that's too technical, maybe there's a better phrasing without sacrificing accuracy.

If we don't already, we could also provide a fix-it to add parens. (I didn't realize this is something you could do to fix the issue until today, normally I would hoist the try out to immediately follow the = to resolve this issue).

Copy link

@typesanitizer typesanitizer commented Apr 17, 2021

@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
None yet

No branches or pull requests

1 participant