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-8504] Confusing error message for '<' comparison after 'as' cast #51024

Open
huonw mannequin opened this issue Aug 10, 2018 · 1 comment
Open

[SR-8504] Confusing error message for '<' comparison after 'as' cast #51024

huonw mannequin opened this issue Aug 10, 2018 · 1 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 parser Area → compiler: The legacy C++ parser

Comments

@huonw
Copy link
Mannequin

huonw mannequin commented Aug 10, 2018

Previous ID SR-8504
Radar rdar://problem/27751587
Original Reporter @huonw
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, DiagnosticsQoI, Parser
Assignee None
Priority Medium

md5: 16c5ef9515b96271e36bca5ac9b9e349

Issue Description:

The following code is invalid, as the `as? ...` starts parsing a following type, and Int < ... looks like the start of a generic type.

let x: Any = 0
if x as? Int < Int(0) {}

There's a huge spew of error messages:

lessthan.swift:2:19: error: expected '>' to complete generic argument list
if x as? Int < Int(0) {}
                  ^
lessthan.swift:2:14: note: to match this opening '<'
if x as? Int < Int(0) {}
             ^
lessthan.swift:2:23: error: top-level statement cannot begin with a closure expression
if x as? Int < Int(0) {}
                      ^
lessthan.swift:2:23: error: closure expression is unused
if x as? Int < Int(0) {}
                      ^
lessthan.swift:2:23: note: did you mean to use a 'do' statement?
if x as? Int < Int(0) {}
                      ^
                      do 

The fix for the syntax error is separating the as ... from the comparison, e.g. (x as? Int) < Int(0))

@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 parser Area → compiler: The legacy C++ parser
Projects
None yet
Development

No branches or pull requests

1 participant