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-5494] can't compare multidimensional arrays for equality in Swift 4 #48066
Comments
Okay, it doesn't work in Swift 3 either. So now I'm not sure when it stopped working. But it did once work, because I've got old code that used it and that has now stopped compiling. So I'm not actually clear on the history, sorry. |
Cannot use flatMap as a workaround because you can get false positives: let arr1 = [[0],[1,2]]
let arr2 = [[0,1],[2]]
let ok = arr1.flatMap{$0} == arr2.flatMap{$0} // true, but that's not the "right" answer |
It has never worked properly. If you have Foundation imported it used to convert to NSArray and compare those, and it no longer does that. |
I don't quite see why that's a resolution. It's an array. Arrays are compared for equality by comparing their elements in order for equality. The elements are arrays, so they can be compared for equality. Why doesn't the language just do this? What am I expected to do here — implement my own completely unnecessary `==` override? |
Array's Element type might not be Equatable, so Array itself can't be declared Equatable until we have conditional conformances. But this is one of the first ones we want to add when we get that! |
It will "just work" when we get conditional conformances. In the meantime, you could use the `elementsEqual` method, or cast the arrays explicitly `as NSArray` to get back to the Swift 2 behavior. |
@jckarter Thanks as always; `elementsEqual` is a great suggestion. I guess I don't quite understand why that isn't exactly what `==` falls back on by default; but at least it does precisely what's needed. |
Environment
Xcode Version 9.0 beta 3 (9M174d)
Additional Detail from JIRA
md5: b7d9f98045b644a724915626edb9d54d
duplicates:
Issue Description:
The following doesn't compile:
This used to work, so I have to wonder whether this is a new Swift 4 bug.
The text was updated successfully, but these errors were encountered: