Files
swift-mirror/test/stdlib/StringCompatibilityDiagnostics.swift
Michael Ilseman 3243b8a59f [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.
2017-08-09 19:41:52 -07:00

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
}