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-851] Result of dropFirst differs between 2.1.1 and 2.2 #43463
Comments
@jepers, out of curiosity, how did you find this issue? I would love to see non-artificial examples. |
I can't remember the exact situation / actual code but I had something like this (in Swift 2.2):
Which compiles fine. And then I needed to change that into something like this:
and I was surprised to see that this modification should cause a compile time error ("Ambiguous use of 'dropFirst'"). Your workaround works for this example, so this compiles fine:
But this leads to the disturbing conclusion that the type of i + j (an Int + an Int) apparently isn't Int in this particular context, and it makes me wonder what other incarnations of this strangeness I might bump into ... Also, I wanted an ArraySlice<Int> (which is what I'll get in Swift 2.1.1) and not an AnySequence<Int> (which is what I get in 2.2). The following example shows how unintuitive / surprising this behavior is in 2.2:
I mean, who would expect b and c to have different types? |
For typechecker, expression `i` is totally different from `i + j`, AFAIK. It IS `Int`, but it is not known immediately, and rather is inferred along with all other types using all the available constrains (actually, adding an extra constrain). Another thing you might want to try in order to help type checker is add `as ArraySlice<YOUR_TYPE_HERE>` at the end of the whole expression, or specify a type for your `b` variable explicitly as `ArraySlice<...>`. This way you should be able to get what you expect without an extra `Array(...)` call. |
Yes, I ended up specifying the type to ArraySlice ... And for what it's worth: I had no problems moving on with my code. My point here is that, well, this is a bug report and this is obviously demonstrating one or more bugs. : ) |
Absolutely. All the bug reports are appreciated. It was not obvious whether you were able to find a workaround, so I tried to give you one... or two. |
Issue remains in Xcode 8 beta 4, with std toolchain and with dev snapshot 2016-08-04. |
Issue remains in Xcode 8 GM, 8.1 beta 1, 2 and 3. |
In Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1), |
Additional Detail from JIRA
md5: 82315efa37acb8595f74c537261fd2a5
is duplicated by:
Issue Description:
Example 1/2
Compiles with Swift 2.1.1 but not with Swift 2.2:
Example 2/2
Compiles in both 2.1.1 and 2.2 but type of result is ArraySlice<String> for 2.1.1 and AnySequence<String> for 2.2:
The text was updated successfully, but these errors were encountered: