File tree Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Expand file tree Collapse file tree 3 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,12 @@ public protocol StringProtocol
78
78
) rethrows -> Result
79
79
}
80
80
81
+ extension StringProtocol /* : LosslessStringConvertible */ {
82
+ public init ? ( _ description: String ) {
83
+ self . init ( description. characters)
84
+ }
85
+ }
86
+
81
87
/// Call body with a pointer to zero-terminated sequence of
82
88
/// `TargetEncoding.CodeUnit` representing the same string as `source`, when
83
89
/// `source` is interpreted as being encoded with `SourceEncoding`.
@@ -1023,12 +1029,6 @@ extension String : CustomStringConvertible {
1023
1029
}
1024
1030
}
1025
1031
1026
- extension String : LosslessStringConvertible {
1027
- public init ? ( _ description: String ) {
1028
- self = description
1029
- }
1030
- }
1031
-
1032
1032
extension String {
1033
1033
@available ( * , unavailable, renamed: " append(_:) " )
1034
1034
public mutating func appendContentsOf( _ other: String ) {
Original file line number Diff line number Diff line change @@ -41,8 +41,8 @@ extension String : StringProtocol {
41
41
// - init<S>(_ characters: S) where S : Sequence, S.Iterator.Element == Character
42
42
// Cannot simply do init(_: String) as that would itself be ambiguous with
43
43
// init?(_ description: String)
44
- public init<T : StringProtocol> (_ other: T ) {
45
- self.init(other.characters )
44
+ public init(_ other: String ) {
45
+ self.init(other._core )
46
46
}
47
47
48
48
/// The position of the first character in a nonempty string.
Original file line number Diff line number Diff line change @@ -362,9 +362,12 @@ StringTests.test("CompareStringsWithUnpairedSurrogates")
362
362
}
363
363
364
364
StringTests . test ( " String.init(_:String) " ) {
365
- let _: String = String ( " " as String ) // should compile without ambiguities
365
+ var s = String ( " " )
366
+ expectType ( String . self, & s)
367
+ var _ = String ( " " ) as String ? // should also compile, but not be the default
366
368
}
367
369
370
+
368
371
StringTests . test ( " [String].joined() -> String " ) {
369
372
let s = [ " hello " , " world " ] . joined ( )
370
373
_ = s == " " // should compile without error
You can’t perform that action at this time.
0 commit comments