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-6999] Changed return type of lazy.prefix(through:).filter() from Swift 4.0 to 4.1 #49547
Comments
Changing behavior does not make something "source-breaking", but it's true that someone could have been relying on string conversion for the result of this operation. |
Ignore the string conversion; that was just to visually show the problem. The actual return type is different. |
Put another way: the bug is not in the print statement, it’s in the fact that the type of the argument to print is different on different versions. |
I would probably put this in the "additive overloading features can break source by shadowing but we don't consider them source breaking" column. Note you can get the original behavior via type context i.e. let a: Array = coll.lazy.prefix(through: 50).filter { $0 % 2 == 0 } |
Right. It's only a bug because of the string conversion, or rather the conversion to Any. In most other cases it will "just work" (either use in an Array context, or use as a general Collection); with a few rare cases you'd get a static type error. |
Ah cool, I see what you're getting at. So just to clarify, this is not considered a breaking change if the new type can be fixed up by the compiler to get the old one instead? |
The compiler isn't fixing anything. The old function, that produced an array, is still there. The type context just ensures that one gets called instead of the newer, more-specific, overload. |
Additional Detail from JIRA
md5: 0c9f78c22e57cb25e86de2a1304d694e
Issue Description:
Consider the following program:
On the released Swift 4.0.2, this is the printed result:
However, on the Swift 4.1 2018-02-13a snapshot, the printed result is:
This represents a change in return type, from
Array<Int>
toLazyFilterCollection<Slice<LazyCollection<LazyHundredCollection>>>
. While I appreciate that this potentially (I say "potentially" because of SR-6991) fixes the above misbehaviour of non-lazily iterating the collection, this is a source breaking change and presumably should be delayed to Swift 5.The text was updated successfully, but these errors were encountered: