Skip to content

[stdlib] Remove the unnecessary compactMap overload #14769

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

Merged
merged 1 commit into from
Feb 21, 2018

Conversation

moiseev
Copy link
Contributor

@moiseev moiseev commented Feb 21, 2018

This particular overload of compactMap was mechanically copied from the flatMap while implementing SE-0187, but as community members correctly noticed on the forum thread here, there is no code that we should be backward compatible with, sincecompactMap has only been introduced recently.

After applying this change, the following code is correctly ambiguous again:

[].compactMap { _ in nil } // error: 'nil' requires a contextual type

as opposed to:

[].flatMap { _ in nil } // r0 : [String] = []

Fixes: https://bugs.swift.org/browse/SR-7052

This particular overload of compactMap was mechanically copied from the
`flatMap` while implementing SE-0187, but as community members correctly
noticed on the forum thread
[here](https://forums.swift.org/t/why-is-there-a-collection-flatmap-that-takes-a-closure-returning-string/10141),
there is no code that we should be backward compatible with, since
`compactMap` has only been introduced recently.

After applying this change, the following code is correctly ambiguous
again:

```swift
[].compactMap { _ in nil } // error: 'nil' requires a contextual type
```

as opposed to:

```swift
[].flatMap { _ in nil } // r0 : [String] = []
```

Fixes: https://bugs.swift.org/browse/SR-7052
@moiseev
Copy link
Contributor Author

moiseev commented Feb 21, 2018

@swift-ci Please smoke test

@moiseev
Copy link
Contributor Author

moiseev commented Feb 21, 2018

@swift-ci Please Test Source Compatibility

@DevAndArtist
Copy link
Contributor

Simplest solution ever :D

@moiseev moiseev merged commit 01c2c85 into swiftlang:master Feb 21, 2018
@moiseev moiseev deleted the no-weird-overload branch February 21, 2018 23:59
@moiseev
Copy link
Contributor Author

moiseev commented Feb 23, 2018

Cherry-picked into #14779 and #14804

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants