Skip to content
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

[stdlib] Backward compatibility fix for a flatMap on [String] #9466

Merged
merged 2 commits into from May 11, 2017

Conversation

moiseev
Copy link
Contributor

@moiseev moiseev commented May 10, 2017

Since String started to conform to Collection, the flatMap with a
sequence returning closure is now a better match than the one that
relies on the optional promotion in this code:

[""].flatMap { $0 }

which results in the default type of this expression changing from
[String] to [Character].

Restoring the old behavior in Swift 3 mode by adding a very explicit
overload.

Fixes: rdar://problem/32024978

@moiseev
Copy link
Contributor Author

moiseev commented May 10, 2017

/cc @dabrahams , @airspeedswift

@moiseev
Copy link
Contributor Author

moiseev commented May 10, 2017

@swift-ci Please test

@moiseev
Copy link
Contributor Author

moiseev commented May 10, 2017

@swift-ci Please Test Source Compatibility

Since String started to conform to Collection, the flatMap with a
sequence returning closure is now a better match that the one that
relies on the optional promotion in this code:

[""].flatMap { $0 }

which results in the default type of this expression changing from
[String] to [Character].

Restoring the old behavior in Swift 3 mode by adding a very explicit
overload.

Fixes: <rdar://problem/32024978>
@moiseev
Copy link
Contributor Author

moiseev commented May 11, 2017

@swift-ci Please smoke test

@moiseev
Copy link
Contributor Author

moiseev commented May 11, 2017

@swift-ci Please Test Source Compatibility

@moiseev
Copy link
Contributor Author

moiseev commented May 11, 2017

@swift-ci Please Test Source Compatibility

@moiseev
Copy link
Contributor Author

moiseev commented May 11, 2017

@swift-ci Please smoke test

@airspeedswift airspeedswift merged commit 31f7dfe into apple:master May 11, 2017
@moiseev moiseev deleted the flatmap-string branch May 11, 2017 16:24
@Coeur
Copy link
Contributor

Coeur commented Jun 25, 2017

Fixes: rdar://problem/32024978

Can someone fill http://www.openradar.me/32024978 or provide a public resource?

@moiseev
Copy link
Contributor Author

moiseev commented Jun 26, 2017

@Coeur The description of this PR explains it, doesn't it?

The following code:

struct S { var p: String }

func f(xs: [S]) -> [String] {
   return xs.flatMap { $0.p }
}

would not compile once String becomes Collection without this fix, with the error being something like 'cannot convert [Character] to return type [String]'.

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.

None yet

3 participants