Skip to content

Commit 4be8144

Browse files
committed
[stdlib] Optional, Result: Try adding @_disfavoredOverload to work around a shadowing issue
The new ~Copyable generalizations have changed the function signature enough that alternative definitions of `map`/`flatMap` in existing code that used to be considered to shadow the originals no longer do so. This leads to use sites becoming ambiguous — a source break. While we consider approaches to resolve this on the compiler side, let’s try slapping a `@_disfavoredOverload` on these and see if that helps. (cherry picked from commit c6bc196)
1 parent 4cdccaf commit 4be8144

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

stdlib/public/core/Optional.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ extension Optional {
186186
/// - Returns: The result of the given closure. If this instance is `nil`,
187187
/// returns `nil`.
188188
@_alwaysEmitIntoClient
189+
@_disfavoredOverload // FIXME: Workaround for source compat issue with
190+
// functions that used to shadow the original map
191+
// (rdar://125016028)
189192
public func map<E: Error, U: ~Copyable>(
190193
_ transform: (Wrapped) throws(E) -> U
191194
) throws(E) -> U? {
@@ -264,6 +267,9 @@ extension Optional {
264267
/// - Returns: The result of the given closure. If this instance is `nil`,
265268
/// returns `nil`.
266269
@_alwaysEmitIntoClient
270+
@_disfavoredOverload // FIXME: Workaround for source compat issue with
271+
// functions that used to shadow the original flatMap
272+
// (rdar://125016028)
267273
public func flatMap<E: Error, U: ~Copyable>(
268274
_ transform: (Wrapped) throws(E) -> U?
269275
) throws(E) -> U? {

stdlib/public/core/Result.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ extension Result {
4949
/// - Returns: A `Result` instance with the result of evaluating `transform`
5050
/// as the new success value if this instance represents a success.
5151
@_alwaysEmitIntoClient
52+
@_disfavoredOverload // FIXME: Workaround for source compat issue with
53+
// functions that used to shadow the original map
54+
// (rdar://125016028)
5255
public func map<NewSuccess: ~Copyable>(
5356
_ transform: (Success) -> NewSuccess
5457
) -> Result<NewSuccess, Failure> {
@@ -187,6 +190,9 @@ extension Result {
187190
/// - Returns: A `Result` instance, either from the closure or the previous
188191
/// `.failure`.
189192
@_alwaysEmitIntoClient
193+
@_disfavoredOverload // FIXME: Workaround for source compat issue with
194+
// functions that used to shadow the original flatMap
195+
// (rdar://125016028)
190196
public func flatMap<NewSuccess: ~Copyable>(
191197
_ transform: (Success) -> Result<NewSuccess, Failure>
192198
) -> Result<NewSuccess, Failure> {

0 commit comments

Comments
 (0)