mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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.
15 lines
623 B
Swift
15 lines
623 B
Swift
// 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() // TODO: deprecate the view, and update the error here
|
|
_ = 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
|
|
}
|
|
|