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

Missing diagnostic for invalid operator usage in for loop #79999

Open
alimyuz opened this issue Mar 13, 2025 · 0 comments · May be fixed by #80042
Open

Missing diagnostic for invalid operator usage in for loop #79999

alimyuz opened this issue Mar 13, 2025 · 0 comments · May be fixed by #80042
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@alimyuz
Copy link

alimyuz commented Mar 13, 2025

Description

Passing an operator (-, +, *, /) as a function argument inside a for loop fails to produce a proper diagnostic. Outside of a for loop, the correct diagnostic is produced.
This is reproducible with any type of parameter, not only numerical.

Reproduction

func example(_ a: Int) -> [Int] { [] } // 'a' can be any type: String, Data, custom type, etc.

let _ = foo(-) // Type of expression is ambiguous without a type annotation (expected diagnostic)

for _ in foo(-) { // Failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
} 

Expected behavior

Build error with appropriate diagnostic.

Environment

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: arm64-apple-macosx15.0
Xcode 16.2 (16C5032a)

Additional information

No response

@alimyuz alimyuz added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Mar 13, 2025
Rajveer100 added a commit to Rajveer100/swift that referenced this issue Mar 16, 2025
Resolves swiftlang#79999

Snippet:

```
func foo(_ a: Int) -> [Int] { [] }
for _ in foo(-) {}
```
Rajveer100 added a commit to Rajveer100/swift that referenced this issue Mar 16, 2025
Resolves swiftlang#79999

Snippet:

```
func foo(_ a: Int) -> [Int] { [] }
for _ in foo(-) {}
```
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. triage needed This issue needs more specific labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant