Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[stdlib] Availability checking for String.*View.popFirst
Collection's popFirst is only present when the Collection is its own SubSequence type. String and String's views are no longer their own SubSequenes, so popFirst is no longer present. Unfortunately, this breaks code in swift-version 3 and it also gives a terrible diagnostic to users. This change introduces an implementation for swift-version 3 mode and better diagnostics for Swift 4 code. Tests included.
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// RUN: %swift -typecheck -swift-version 4 %s -verify | ||
|
||
func testPopFirst() { | ||
var str = "abc" | ||
_ = str.popFirst() // expected-error{{'popFirst()' is unavailable: Please use 'first', 'dropFirst()', or 'Substring.popFirst()'}} | ||
_ = str.characters.popFirst() // expected-error{{'popFirst()' is unavailable: Please use 'first', 'dropFirst()', or 'Substring.CharacterView.popFirst()'}} | ||
_ = str.unicodeScalars.popFirst() // expected-error{{'popFirst()' is unavailable: Please use 'first', 'dropFirst()', or 'Substring.UnicodeScalarView.popFirst()'}} | ||
|
||
var substr = str[...] | ||
_ = substr.popFirst() // ok | ||
_ = substr.characters.popFirst() // ok | ||
_ = substr.unicodeScalars.popFirst() // ok | ||
} | ||
|