swift-syntax icon indicating copy to clipboard operation
swift-syntax copied to clipboard

[SR-778] Forgetting the in keyword can sometimes lead to compiling code

Open swift-ci opened this issue 9 years ago • 13 comments

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 Missing @warn_unused_result attributes in Standard Library

Issue Description:

Try the following code:

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.

swift-ci avatar Feb 20 '16 12:02 swift-ci