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-8736] Bad diagnostic for use of trailing closures in an if #51245

Closed
swift-ci opened this issue Sep 13, 2018 · 3 comments
Closed

[SR-8736] Bad diagnostic for use of trailing closures in an if #51245

swift-ci opened this issue Sep 13, 2018 · 3 comments

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 13, 2018

Previous ID SR-8736
Radar None
Original Reporter nhatlee89 (JIRA User)
Type Bug
Status Closed
Resolution Duplicate

Attachment: Download

Environment

MacOS 10.13.5, Xcode 9.4.1, Swift 4.2

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, Parser
Assignee owenvoorhees (JIRA)
Priority Medium

md5: 99b5b574037577a367a74dc8e3a41396

duplicates:

  • SR-5869 trailing closure not parsed correctly in if-statement conditional

Issue Description:

I use Swift 4.2 and got the error with below code:

let maxValue = Float(max(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height)) 
let dicQuality = profileConfig?.getImageQuality() ?? [String: Any]() 
let quality: Float = 0.5 
if let keyMap = dicQuality.keys.sorted { $0.toFloat(defaultValue: 0) > $1.toFloat(defaultValue: 0) }.first(where: { maxValue <= $0.toFloat(defaultValue: 0) }) { 
  return dicQuality.float(forKey: keyMap, defaultValue: 0.5) 
} 
return quality

But when I change to below code, it can build success:

let maxValue = Float(max(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height)) 
let dicQuality = profileConfig?.getImageQuality() ?? [String: Any]() 
let quality: Float = 0.5 
let keyMap = dicQuality.keys.sorted { $0.toFloat(defaultValue: 0) > $1.toFloat(defaultValue: 0) }.first(where: { maxValue <= $0.toFloat(defaultValue: 0) }) 
if let key = keyMap { 
return dicQuality.float(forKey: key, defaultValue: 0.5) 
} 
return quality

The error is:
![](Screen Shot 2018-09-12 at 2.17.48 PM.png)

@belkadan
Copy link
Contributor

belkadan commented Sep 13, 2018

(As noted on the forums, this is because trailing closure syntax isn't supported in the condition of an if or guard. This bug is about improving the diagnostics if possible.)

@swift-ci
Copy link
Collaborator Author

swift-ci commented May 31, 2019

Comment by Owen Voorhees (JIRA)

Opened a PR here to try and improve the diagnostic in cases like this: #25165

@swift-ci
Copy link
Collaborator Author

swift-ci commented Nov 22, 2019

Comment by Owen Voorhees (JIRA)

This is a duplicate of SR-5869 (which is now fixed)

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

No branches or pull requests

2 participants