-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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-6103] Law of Exclusivity is not applied for extension of Array with closure which returns Element #48658
Comments
@devincoughlin, @rjmccall, any insights? |
The type-specificity suggests that this is related to the code-generation differences for an indirect-out parameter, but I don't know why. Regardless, clearly a bug. |
Ah, it's the reabstraction thunk. |
Reduced test case:
|
Probably possible to address this directly with the current representation, but might be easier to fix if we had a reabstract_function instruction. |
Tracking internally as rdar://35215926. |
There is a fix in #12929 |
Should be fixed in #12929 Thanks for reporting the issue! |
Thanks to fix it. Sorry, why am I set to assignee ? |
We assign the bug to the originator so you can confirm that the the bug is fixed and close the JIRA issue. If you have time, it would be helpful if you could download a nightly toolchain from swift.org and confirm that the bug is fixed. This helps us make sure that we fixed the bug properly. If you don't have the time, then you can close the JIRA issue. |
Thanks Devin to explain for me. |
I checked with snapshot at 2017/11/21. Unfortunately compiler is still wrong a little. Of course If I change `Element` to `Int` at line 2, This is log. [omochi@omochi-iMac bbb]$ cat a.swift
extension Array {
mutating func update(_ f: () -> Element) {}
}
func main() {
var xs: [Int] = [1, 2, 3]
var ys: [Int] = []
xs.update {
ys = xs
return 3
}
}
main()
[omochi@omochi-iMac bbb]$ export TOOLCHAINS=org.swift.3020171121a
[omochi@omochi-iMac bbb]$ swift --version
Apple Swift version 4.1-dev (LLVM fe49d8f2ca, Clang 839070845c, Swift c0c04864db)
Target: x86_64-apple-darwin16.7.0
[omochi@omochi-iMac bbb]$ swift a.swift
a.swift:8:9: warning: variable 'ys' was written to, but never read
var ys: [Int] = []
^
a.swift:9:5: warning: overlapping accesses to 'xs', but modification requires exclusive access; consider copying to a local variable
xs.update {
^~
a.swift:10:12: note: conflicting access is here
ys = xs
~~~^~~~ |
Thanks for for checking this. For Swift 4.1 the new diagnostics will be warnings and not errors. This is for source compatibility. Where possible, we would like to avoid code that compiles with the 4.0 compiler having an error in 4.1. The plan is to turn the new diagnostics into hard errors in a future version of the Swift compiler. |
Oh I see. I close issue. |
thank you |
Environment
I confirmed issue in those environment.
Xcode 9.0 (9A235)
swift-DEVELOPMENT-SNAPSHOT-2017-10-09-a.xctoolchain
Additional Detail from JIRA
md5: d6252cd613b8dadf61dfa718a82d951b
Issue Description:
This code can be compiled incorrectly.
Calling mutating func of `xs` and reading `xs` on right hand of assignment should be conflict.
Strangely, this problem occurs only when `Element` is used at closure result.
If return type changed to `Void`, `Array<Element>` or `Int`,
all cases will be compile error correctly.
This is `Void` case.
The text was updated successfully, but these errors were encountered: