swiftlang / swiftlang/swift-syntax
[SR-778] Forgetting the in keyword can sometimes lead to compiling code
- Dominant language
- Swift
- Stars
- 3.7k
- Forks
- 553
- Avg merge
- 5d 13h
- Merged PRs (30d)
- 16
Description
| | |
|------------------|-----------------|
|Previous ID | SR-778 |
|Radar | None |
|Original Reporter | chriseidhof (JIRA User) |
|Type | Bug |
|Status | Reopened |
|Resolution | |
Additional Detail from JIRA
| | |
|------------------|-----------------|
|Votes | 0 |
|Component/s | Standard Library |
|Labels | Bug |
|Assignee | None |
|Priority | Medium |
md5: 0093a5f05b0f3ded251f13fdd054fe04
**relates to**:
* [SR-245](https://bugs.swift.org/browse/SR-245) Missing @warn_unused_result attributes in Standard Library
**Issue Description:**
Try the following code:
```swift
var x = 0
let capture: () -> Int = { [x]
return x
}
x++
capture()
```
Expected result: because there is a capture list `[x]` that should capture x by value, we expect the result of the final call to be 0. However, it is 1. This is because we forget the in keyword, and `[x]` gets parsed as an array literal.
A possible solution would be to warn about `[x]` being an unused expression.
Contributor guide
Assessment
This issue has not been assessed yet.