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-9893] Swift 5 regression: cannot assign through '!': '$0' is immutable #52299

Open
groue opened this issue Feb 9, 2019 · 1 comment
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression source compatibility swift 5.0

Comments

@groue
Copy link

groue commented Feb 9, 2019

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 :)

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Jul 23, 2019

Should be fixed as of #22526 and #22563 The fix is available in the last Swift release.

@groue, Could you verify if the problem is fixed and if so move the JIRA to "Closed"?

Thanks!
Anna

@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 regression source compatibility swift 5.0
Projects
None yet
Development

No branches or pull requests

2 participants