@@ -66,13 +66,21 @@ Marks an overload that the type checker should try to avoid using. When the
66
66
expression type checker is considering overloads, it will prefer a solution
67
67
with fewer ` @_disfavoredOverload ` declarations over one with more of them.
68
68
69
- Historically, it was designed to help with ` ExpressibleByXYZLiteral ` types.
70
- The type checker strongly prefers to give literals their default type
71
- (e.g. ` Int ` for ` ExpressibleByIntegerLiteral ` ,
72
- ` String ` for ` ExpressibleByStringLiteral ` , etc.).
73
- If an API should prefer some other type, but accept the default too,
74
- marking the declaration taking the default type with ` @_disfavoredOverload `
75
- gives the desired behavior:
69
+ Use ` @_disfavoredOverload ` to work around known bugs in the overload
70
+ resolution rules that cannot be immediately fixed without a source break.
71
+ Don't use it to adjust overload resolution rules that are otherwise sensible
72
+ but happen to produce undesirable results for your particular API; it will
73
+ likely be removed or made into a no-op eventually, and then you will be
74
+ stuck with an overload set that cannot be made to function in the way
75
+ you intend.
76
+
77
+ ` @_disfavoredOverload ` was first introduced to work around a bug in overload
78
+ resolution with ` ExpressibleByXYZLiteral ` types. The type checker strongly
79
+ prefers to give literals their default type (e.g. ` Int ` for
80
+ ` ExpressibleByIntegerLiteral ` , ` String ` for ` ExpressibleByStringLiteral ` ,
81
+ etc.). If an API should prefer some other type, but accept the default too,
82
+ marking the declaration taking the default type with ` @_disfavoredOverload `
83
+ gives the desired behavior:
76
84
77
85
``` swift
78
86
extension LocalizedStringKey : ExpressibleByStringLiteral { ... }
@@ -87,12 +95,6 @@ extension Text {
87
95
}
88
96
```
89
97
90
- ` @_disfavoredOverload ` is a stop-gap design; eventually the type-checker
91
- behavior should be fixed and the attribute should be removed/made into a no-op.
92
-
93
- Its main use case is to work around clearly undesirable overload resolution,
94
- not to arbitrarily manipulate overload priority.
95
-
96
98
## ` @_dynamicReplacement(for:) `
97
99
98
100
Marks a function as the dynamic replacement for another ` dynamic ` function.
0 commit comments