Skip to content

Commit 26bd056

Browse files
committed
stdlib: Add @_disfavoredOverload to various functions for Embedded.
Functions like `fatalError()` have overloads for Embedded Swift only that take StaticString instead of String, since String is unavailable. Unfortunately, many of these overloads create the opportunity for ambiguity in certain contexts. The easiest way to avoid the ambiguities is to mark each of the overloads taking `String` as `@_disfavoredOverload`. Another approach that could work would be to remove the default arguments from the `String` variants in Embedded Swift only, but that would create even more duplication of source code so it doesn't seem worth it.
1 parent 4937282 commit 26bd056

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

stdlib/public/core/Assert.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
/// is called.
4040
@_transparent
4141
@_unavailableInEmbedded
42+
#if $Embedded
43+
@_disfavoredOverload
44+
#endif
4245
public func assert(
4346
_ condition: @autoclosure () -> Bool,
4447
_ message: @autoclosure () -> String = String(),
@@ -99,6 +102,9 @@ public func assert(
99102
/// `precondition(_:_:file:line:)` is called.
100103
@_transparent
101104
@_unavailableInEmbedded
105+
#if $Embedded
106+
@_disfavoredOverload
107+
#endif
102108
public func precondition(
103109
_ condition: @autoclosure () -> Bool,
104110
_ message: @autoclosure () -> String = String(),
@@ -162,6 +168,9 @@ public func precondition(
162168
@inlinable
163169
@inline(__always)
164170
@_unavailableInEmbedded
171+
#if $Embedded
172+
@_disfavoredOverload
173+
#endif
165174
public func assertionFailure(
166175
_ message: @autoclosure () -> String = String(),
167176
file: StaticString = #file, line: UInt = #line
@@ -221,6 +230,9 @@ public func assertionFailure(
221230
/// line number where `preconditionFailure(_:file:line:)` is called.
222231
@_transparent
223232
@_unavailableInEmbedded
233+
#if $Embedded
234+
@_disfavoredOverload
235+
#endif
224236
public func preconditionFailure(
225237
_ message: @autoclosure () -> String = String(),
226238
file: StaticString = #file, line: UInt = #line
@@ -264,6 +276,9 @@ public func preconditionFailure(
264276
/// line number where `fatalError(_:file:line:)` is called.
265277
@_transparent
266278
@_unavailableInEmbedded
279+
#if $Embedded
280+
@_disfavoredOverload
281+
#endif
267282
public func fatalError(
268283
_ message: @autoclosure () -> String = String(),
269284
file: StaticString = #file, line: UInt = #line

0 commit comments

Comments
 (0)