Skip to content

Commit f2baa7a

Browse files
committed
[docs][SR-9915] Compilation fix of docs snippet of type(of:)
Compilation of code sample snippets was broken due to using the same identifier as the `type` function itself to store its result resulting in: ```swift func printGenericInfo<T>(_ value: T) { let type = type(of: value) print("'\(value)' of type '\(type)'") } // error: repl.swift:2:16: error: variable used within its own initial // value // let type = type(of: value) // ^ ``` Result: - Snippets are more copy&paste friendly. - Resolves https://bugs.swift.org/browse/SR-9915
1 parent 458690e commit f2baa7a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

stdlib/public/core/Builtin.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,8 @@ func _trueAfterDiagnostics() -> Builtin.Int1 {
753753
/// declared for the parameter) and a dynamic type of `Int`.
754754
///
755755
/// func printInfo(_ value: Any) {
756-
/// let type = type(of: value)
757-
/// print("'\(value)' of type '\(type)'")
756+
/// let t = type(of: value)
757+
/// print("'\(value)' of type '\(t)'")
758758
/// }
759759
///
760760
/// let count: Int = 5
@@ -816,8 +816,8 @@ func _trueAfterDiagnostics() -> Builtin.Int1 {
816816
/// of `String.self` (the dynamic type inside the parameter).
817817
///
818818
/// func printGenericInfo<T>(_ value: T) {
819-
/// let type = type(of: value)
820-
/// print("'\(value)' of type '\(type)'")
819+
/// let t = type(of: value)
820+
/// print("'\(value)' of type '\(t)'")
821821
/// }
822822
///
823823
/// protocol P {}
@@ -835,8 +835,8 @@ func _trueAfterDiagnostics() -> Builtin.Int1 {
835835
/// calling `type(of:)`.
836836
///
837837
/// func betterPrintGenericInfo<T>(_ value: T) {
838-
/// let type = type(of: value as Any)
839-
/// print("'\(value)' of type '\(type)'")
838+
/// let t = type(of: value as Any)
839+
/// print("'\(value)' of type '\(t)'")
840840
/// }
841841
///
842842
/// betterPrintGenericInfo(stringAsP)

0 commit comments

Comments
 (0)