Thomvis / BrightFutures

Write great asynchronous code in Swift using futures and promises
MIT License
1.9k stars 184 forks source link

localThreadDictionary must be var #204

Closed jgh- closed 5 years ago

jgh- commented 5 years ago

This fixes a build error that occurs when building BrightFutures on Linux with Swift 4.2.3

phimage commented 5 years ago

The message error is? something about cannot be edited some line after? (if yes threadDictionary is a NSMutableDictionary? or it will became a simple Dictionary on linux or futur swift version)

jgh- commented 5 years ago

So it looks like it is an NSMutableDictionary that has been re-implemented with a Dictionary under the hood. The precise error is:

.build/checkouts/BrightFutures--8066460943566260734/Sources/BrightFutures/ExecutionContext.swift:62:52: error: cannot assign through subscript: 'localThreadDictionary' is a 'let' constant
        localThreadDictionary[Static.taskDepthKey] = previousDepth + 1
.build/checkouts/BrightFutures--8066460943566260734/Sources/BrightFutures/ExecutionContext.swift:50:5: note: change 'let' to 'var' to make it mutable
    let localThreadDictionary = Thread.current.threadDictionary
    ^~~
    var

You can see the NSDictionary implementation here: https://github.com/apple/swift-corelibs-foundation/blob/e3f021c462f49e0776657b12e9afaf7ce1dffe42/Foundation/NSDictionary.swift#L14