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-14166] Compiler suggests a wrong insertion point for 'try'. #56545

Open
YOCKOW opened this issue Feb 8, 2021 · 1 comment
Open

[SR-14166] Compiler suggests a wrong insertion point for 'try'. #56545

YOCKOW opened this issue Feb 8, 2021 · 1 comment
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation

Comments

@YOCKOW
Copy link
Collaborator

YOCKOW commented Feb 8, 2021

Previous ID SR-14166
Radar rdar://problem/74103644
Original Reporter @YOCKOW
Type Bug
Environment

Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
Target: x86_64-apple-darwin20.3.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI
Assignee @etcwilde
Priority Medium

md5: d898744436bb988ab41cc5b6acabb33d

Issue Description:

As you can see in the following code, the compiler suggests to write 'try' on the right side of an operator even if it is a non-assignment one.

func nonThrowable() -> Int {
  return 0
}

func throwable() throws -> Int {
  return 0
}

if nonThrowable() == throwable() {}
/*
-- ERROR MESSAGE --
 tryOperator.swift:9:22: error: call can throw but is not marked with 'try'
 if nonThrowable() == throwable() {}
                     ^~~~~~~~~~~
 tryOperator.swift:9:22: note: did you mean to use 'try'?
 if nonThrowable() == throwable() {}
                     ^
                     try
 tryOperator.swift:9:22: note: did you mean to handle error as optional value?
 if nonThrowable() == throwable() {}
                     ^
                     try?
 tryOperator.swift:9:22: note: did you mean to disable error propagation?
 if nonThrowable() == throwable() {}
                     ^
                     try!
 */

// Fix it as the compiler says...

if nonThrowable() == try throwable() {}
/*
 -- ERROR MESSAGE --
 tryOperator.swift:29:22: error: 'try' cannot appear to the right of a non-assignment operator
 if nonThrowable() == try throwable() {}
                      ^
 */
@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
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself diagnostics QoI Bug: Diagnostics Quality of Implementation
Projects
None yet
Development

No branches or pull requests

2 participants