Skip to content

[stdlib] Reverting the String.init?(_: String) behavior #9659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions stdlib/public/core/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,6 @@ public protocol StringProtocol
) rethrows -> Result
}

extension StringProtocol /* : LosslessStringConvertible */ {
// This overload is for the Swift 3 compatibility.
// In Swift 4, conformance is satisfied by the non-failable initializer, so
// that `String("") as String?` is still possible, but `String("")!` is not.
@available(swift, obsoleted: 4,
message: "Please use the non-failable initializer.")
public init?(_ description: String) {
self.init(description.characters)
}
}

/// Call body with a pointer to zero-terminated sequence of
/// `TargetEncoding.CodeUnit` representing the same string as `source`, when
/// `source` is interpreted as being encoded with `SourceEncoding`.
Expand Down
12 changes: 8 additions & 4 deletions stdlib/public/core/StringRangeReplaceableCollection.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,16 @@ extension String : StringProtocol {
}

// FIXME(strings): doc comment
// This initializer satisfies the conformance to LosslessStringConvertible
// and disambiguates between the following intitializers, now that String
// conforms to Collection:
// This initializer disambiguates between the following intitializers, now
// that String conforms to Collection:
// - init<T>(_ value: T) where T : LosslessStringConvertible
// - init<S>(_ characters: S) where S : Sequence, S.Element == Character
public init(_ other: String) {
public init<T : StringProtocol>(_ other: T) {
self.init(other.characters)
}

// This initializer satisfies the LosslessStringConvertible conformance
public init?(_ other: String) {
self.init(other._core)
}

Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/Substring.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,11 @@ extension String {
extension Substring {
@available(swift, obsoleted: 4)
public subscript(bounds: Range<Index>) -> String {
return String(self[bounds])
return String(characters[bounds])
}

@available(swift, obsoleted: 4)
public subscript(bounds: ClosedRange<Index>) -> String {
return String(self[bounds] as Substring)
return String(characters[bounds])
}
}
5 changes: 0 additions & 5 deletions test/stdlib/StringAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,6 @@ StringTests.test("CompareStringsWithUnpairedSurrogates")
)
}

StringTests.test("String.init(_:String)/default type") {
var s = String("")
expectType(String.self, &s)
}

StringTests.test("[String].joined() -> String") {
let s = ["hello", "world"].joined()
_ = s == "" // should compile without error
Expand Down
2 changes: 1 addition & 1 deletion test/stdlib/StringCompatibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Tests.test("ClosedRange/Subsript/ExpectedType") {

Tests.test("String.init(_:String)/default type") {
var s = String("")
expectType(String.self, &s)
expectType(String?.self, &s)
}

Tests.test("LosslessStringConvertible/generic") {
Expand Down