Description
Previous ID | SR-9893 |
Radar | rdar://problem/47967277 |
Original Reporter | @groue |
Type | Bug |
Environment
Xcode Version 10.2 beta 2
Swift 5 toolchain 06/02/2019
macOS 10.14.3 (18D109)
Additional Detail from JIRA
Votes | 0 |
Component/s | Compiler |
Labels | Bug, 5.0Regression, SourceCompatibility |
Assignee | None |
Priority | Medium |
md5: ac90bc1287842cec66ca4d2c3e628f0b
Issue Description:
I have a test which won't compile with the Swift 5 compiler (2019-02-06 snapshot), both in Swift 5 and Swift 4.2 modes:
XCTAssertEqual(
Set(fetchedRecords.map { $0.name! }),
Set([record1, record2].map { $0.name! }))
The compiler emits the following error:
/Users/groue/Documents/git/groue/GRDB.swift/Tests/GRDBTests/RecordPrimaryKeyNoneTests.swift:155:106: error: cannot assign through '!': '$0' is immutable
XCTAssertEqual(Set(fetchedRecords.map { $0.name! }), Set([record1, record2].map { $0.name! }))
~~ ^
The error vanishes when the code is rewritten in the equivalent form below:
let fetchedNames = Set(fetchedRecords.map { $0.name! })
let expectedNames = Set([record1, record2].map { $0.name! })
XCTAssertEqual(fetchedNames, expectedNames)
For information, the record1, record2 variables are of type `Item`, and the fetchedRecords variable is of type `[Item]`:
private class Item: Record {
var name: String?
...
}
To reproduce:
1. Clone https://github.com/groue/GRDB.swift.git
2. Checkout the 493575a47bc7feffecd91bdd411358e15f92e118 commit
3. Open GRDB.xcworkspace
4. Select the GRDBOSX scheme
5. Build tests with the 2019-02-06 snapshot > there is an error :(
6. Build tests with Xcode 10.1 > there is no error :)