[swift-corelibs-dev] Closure fail to infer parameter type in a rare situation
Yilei He
lionhylra at gmail.com
Fri Jul 7 02:26:04 CDT 2017
Hi,
I found a very rare situation that closure can’t infer the type of its parameter. See the code below:
> ```
> func withReference<T, Result>(_ value: inout T, _ execute: (inout T) throws -> Result) rethrows -> Result {
> return try execute(&value)
> }
>
> struct Person {
> var name: String
> }
>
> var p = Person(name: "a")
>
> withReference(&p) { (v) in
> v.name = "1"
> }
>
> print(p)
> ```
The code can be compiled and produce correct result in Swift 3(Xcode 8) playground, but it can’t be compiled in Swift 4(Xcode 9 beta2).
The error says:
> error: bug.playground:11:7: error: type of expression is ambiguous without more context
> v.name = "1"
> ~~^~~~
Is this related to exclusive access rule introduced to Swift 4?
Regards,
Yilei He
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-corelibs-dev/attachments/20170707/93f5bb88/attachment.html>
More information about the swift-corelibs-dev
mailing list